generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Roblox » All Things ROBLOX
Home Search
 

Re: What is LocalPlayer!

Previous Thread :: Next Thread 
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:20 AM
I haven't been on roblox in a while and some things have changed. I am trying to make a script work online, it only works in play solo because the code command i used was game.Players.LocalPlayer.

This doesnt work in online but it works in play solo, is there any command or list of commands that could substitiute LocalPlayer and make it work in online servers with multiple players.

Yes i am aware this should be in scripting helpers but nobody is actually helping me.
Report Abuse
Qolio is not online. Qolio
Joined: 28 Sep 2014
Total Posts: 1754
01 Oct 2014 11:20 AM
There is a flaw otherwise in the script.
Report Abuse
ManyFireman is not online. ManyFireman
Joined: 19 Sep 2010
Total Posts: 2887
01 Oct 2014 11:20 AM
localplayer
is
localplayer
duh
Report Abuse
DarkComa is not online. DarkComa
Joined: 01 Apr 2011
Total Posts: 11679
01 Oct 2014 11:21 AM
basically it means u can access ur local shops and become local

so u can buy local milk

now ur local player
Report Abuse
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:21 AM
i can post the whole script but im am uncertain if it will make any sense to you.
Report Abuse
ManyFireman is not online. ManyFireman
Joined: 19 Sep 2010
Total Posts: 2887
01 Oct 2014 11:22 AM
ot is kind and helpful
Report Abuse
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:23 AM
yes i am aware what local player does i am looking for a substitute command that would work for online servers and multiple players.
Report Abuse
DarkComa is not online. DarkComa
Joined: 01 Apr 2011
Total Posts: 11679
01 Oct 2014 11:23 AM
wow do not be deceived by other players

local player means u can access ur local shops n stuff

retweet this if u agree
Report Abuse
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:26 AM
Here is the full scripts the line with "//" before it is the problem

_G[script.Name] = {}
local gFunctions = _G[script.Name]

local server = workspace.Server
local resources = game.Lighting.Resources

// local player = game.Players.LocalPlayer
local camera = workspace.Camera
local mouse = player:GetMouse()
local character = nil
local torso = nil
local findPartOnRay = workspace.FindPartOnRayWithIgnoreList
local stepped = game:GetService("RunService").Stepped
local Utils
Spawn(function() Utils = assert(LoadLibrary("RbxUtility")) print("loaded") end) --This is tricky...

local runSpeed = 16
local armYaw = 0
local lastLanding = tick()
local inAir = false
local canJump = true
local objects = {}
local rig = {}
local weaponStats = {}
local weaponSounds = {}

local equipped
local weaponInfo = {}

local weaponEnabled = false
local shooting = false
local aiming = false
local reloading = false
local moving = false
local sprinting = false
local stunned = false
local stopping = false

local recoilId
local lastFire = -tick()
local lastSwitch = -tick()

local laC0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
local raC0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
local lhC0alt = CFrame.new(-1, -1, 0) * CFrame.Angles(math.rad(-10), math.rad(-79), math.rad(-9))
local rhC0alt = CFrame.new(1, -1, 0) * CFrame.Angles(math.rad(-2), math.rad(86), math.rad(3))
local lhC0 = CFrame.new(-1, -1, 0) * CFrame.Angles(0, -math.pi/2, 0)
local rhC0 = CFrame.new(1, -1, 0) * CFrame.Angles(0, math.pi/2, 0)
local nC0 = CFrame.new(0, 1, 0) * CFrame.Angles(-math.pi/2, 0, math.pi)
local armPitch = 0
local torsoAngle = 45
local neckRoll = 0
local height = 3
local lastStep = -time()
local velocity = false

local tiltUp = false
local zeroValue = 1
local tiltValue = 0
local verGoal, horGoal = 0, 0
local verCur, horCur = 0, 0
local lastPitch, lastYaw = 0, 0
local xTilt, yTilt, zTilt = 0, 0, 0
local zIn = 0

local bindings = { --we'll move this later (one of these days)
["w"] = "forward",
["a"] = "left",
["s"] = "backward",
["d"] = "right",
[" "] = "jump",
[string.char(17)] = "forward",
[string.char(20)] = "left",
[string.char(18)] = "backward",
[string.char(19)] = "right",
}
local movement = {
["forward"] = false,
["left"] = false,
["backward"] = false,
["right"] = false,
["jump"] = false,
["sprint"] = false,
["crouch"] = false
}

local events = {} --For event connections

function waitForObjects(parent, ...)
for _, child in pairs({...}) do
if not parent:FindFirstChild(child) then
repeat parent.ChildAdded:wait() until parent:FindFirstChild(child)
end
end
end

function destroy(parent, ...)
for i, v in pairs({...}) do
if parent:FindFirstChild(v) then
parent[v]:Destroy()
end
end
end

function createValue(type, parent, name, value)
local valueObj = Instance.new(type, parent)
valueObj.Value = value
valueObj.Name = name
end

function Wait(frames, exception)
for i = 1, frames do
if not exception then return end
stepped:wait()
end
end

function weldParts(parent, p0, p1, c0, c1)
local weld = Instance.new("Weld", parent)
weld.Part0 = p0
weld.Part1 = p1
weld.C0 = c0 or CFrame.new()
weld.C1 = c1 or CFrame.new()
return weld
end

function constrain(val, min, max)
val = math.min(val, max)
val = math.max(val, min)
return val
end

function getPitch(cframe)
local x = cframe.lookVector.X
local y = cframe.lookVector.Y
local z = cframe.lookVector.Z
local rise = y
local run = -math.sqrt(x^2 + z^2)
local pitchValue = -math.atan2(rise, run) + math.rad(180)
return pitchValue
end

function getYaw(cframe)
return (cframe.lookVector * Vector3.new(1,0,1)).unit
end
--collide does it ignore non-cancollide objects?
function advHit(ray, table, collide, visible) --visible does it ignore invisible objects?
local ignore = table
local obj, pos = findPartOnRay(workspace, ray, ignore)
if not obj or ((obj.CanCollide == collide or not collide) and ((obj.Transparency < 1) or not visible)) then
return obj, pos
else
ignore[#ignore + 1] = obj
return advHit(ray, ignore, collide, visible)
end
end

function getMovementVector(look)
local forwardUnit = (look.lookVector * Vector3.new(1, 0, 1)).unit
local strafeUnit = ((look * CFrame.Angles(0, math.rad(90), 0)).lookVector * Vector3.new(1, 0, 1)).unit
local forward = (movement.forward and 1 or 0) - (movement.backward and 1 or 0)
local strafe = (movement.left and 1 or 0) - (movement.right and 1 or 0)
local mv = (forward * forwardUnit + strafe * strafeUnit)
if math.abs(mv.X) + math.abs(mv.Y) + math.abs(mv.Z) > 0 then moving = true mv = mv.unit else moving = false end
return mv
end

function findFloor(moveVector)
local ray = Ray.new(torso.Position + moveVector * Vector3.new(.5,.5,.5), (Vector3.new(0,-6,0)).unit * 4.5)
return advHit(ray, {character, workspace.Camera, server}, true, false)
end

function sprintOn()
if shooting or stunned or stopping then
return
elseif aiming then aimOff() end
if movement.crouch then
crouchOff()
end
movement.sprint = true
local angle = weaponStats.Type == "Pistol" and CFrame.Angles(0, math.rad(-60), 0) * CFrame.new(0, 1.35, -0.3)
or (CFrame.Angles(0, 0, math.rad(-15)) * CFrame.Angles(math.rad(13), math.rad(-67), 0)) * CFrame.new(-0.8, -0.2, -0.4)
local angle2 = weaponStats.Type == "Pistol" and CFrame.Angles(math.rad(-60), math.rad(60), 0) or CFrame.new()
while movement.sprint do
if sprinting then
repeat
_G.Animate.tweenWeld(rig.baseWeld, 1, angle2 * CFrame.new(0, 0.15, .2) * angle, 5, false)
Wait(5, sprinting)
if not sprinting then break end
_G.Animate.tweenWeld(rig.baseWeld, 1, angle2 * CFrame.new(0, 0.35, 0) * angle, 4, false)
Wait(4, sprinting)
if not sprinting then break end
_G.Animate.tweenWeld(rig.baseWeld, 1, angle2 * CFrame.new(0, 0.15, -.2) * angle, 5, false)
Wait(5, sprinting)
if not sprinting then break end
_G.Animate.tweenWeld(rig.baseWeld, 1, angle2 * CFrame.new(0, 0.35, 0) * angle, 4, false)
Wait(4, sprinting)
until not sprinting
_G.Animate.tweenWeld(rig.baseWeld, 0, CFrame.new(), 6, false)
stopping = true
Wait(4)
stopping = false
end
wait(0)
end
end

function sprintOff()
stopping = true
movement.sprint = false
wait(.22)
stopping = false
end

function crouchOn()
if sprinting then return end
movement.crouch = true
end

function crouchOff()
movement.crouch = false
end

function recoilCam(angle, sway, timeUp, timeDown, ratio)
recoilId = (recoilId or 0)+ 1 % 20
local framesUp = math.ceil(timeUp*50)
local framesDown = math.ceil(timeDown*50) * ratio
Spawn(function()
local current = recoilId
for i = 1, framesUp do
if current ~= recoilId then break end
camera.Focus = camera.CoordinateFrame * CFrame.Angles(math.rad(angle/framesUp),math.rad(sway/framesUp),0) * CFrame.new(0,0,-1)
wait(1/50)
end
for i = 1, framesDown do
if current ~= recoilId then break end
camera.Focus = camera.CoordinateFrame * CFrame.Angles(math.rad(-angle/framesDown),math.rad(-sway/framesDown),0) * CFrame.new(0,0,-1)
wait(1/50)
end
end)
end

function makeArms()
if rig.vmLA then
rig.vmLA:Destroy()
end
if rig.vmRA then
rig.vmRA:Destroy()
end
rig.vmLA = resources.Models.Arm:Clone()
rig.vmLA.Name = "Left Arm"
rig.vmLA.Parent = camera
rig.vmRA = rig.vmLA:Clone()
rig.vmRA.Name = "Right Arm"
rig.vmRA.Parent = camera
end

function equipWeapon(equipSlot, weaponId, isDrop, bullets, oldBulletStorage, oldMagType)
unequip()
local newStats = _G.JSON.DecodeJSON(resources.Weapons[tostring(weaponId)].Stats.Value)
weaponStats = {}
for name, value in pairs(newStats) do
weaponStats[name] = value
end
weaponInfo[equipSlot] = {}
local slot = weaponInfo[equipSlot]
equipped = equipSlot

slot.name = weaponStats.WeaponName
if not isDrop then
slot.bulletStorage = weaponStats.CapacityPerMag * 2
slot.bulletsInMag = weaponStats.CapacityPerMag
else
if newStats.Magazine == oldMagType then
slot.bulletStorage = oldBulletStorage
else
slot.bulletStorage = 0
end
slot.bulletsInMag = bullets
end

slot.id = weaponId.Name
slot.weapon = weaponId
slot.weaponStats = weaponStats
slot.firingMode = weaponStats.FireType
slot.animations = weaponId.Animations.Value
loadWeapon(slot.weapon)

weaponEnabled = true
end

function switchWeapon(slotNum)
if tick() - lastSwitch < 0.1 or not weaponInfo[slotNum] or reloading or not weaponInfo[slotNum] then return end
lastSwitch = tick()

unequip()
local slot = weaponInfo[slotNum]
weaponStats = slot.weaponStats
_G.HUD.updateWeaponInfo(slot.bulletsInMag, slot.bulletStorage, slot.name, slot.firingMode)
equipped = slotNum
loadWeapon(slot.weapon)
end

function loadWeapon(weaponId)
local slot = weaponInfo[equipped]
rig.animationSet = slot.animations
armYaw = weaponStats.Type == "Pistol" and -20 or 15

local weaponViewModel = weaponId.ViewModel:Clone()
rig.vmWeapon = weaponViewModel
weaponViewModel.Parent = rig.viewModel
rig.vmBaseWeld = weldParts(weaponViewModel.Base, weaponViewModel.Base, rig.viewBase)
rig.vmBaseWeld.C0 = CFrame.new(-.65, .28, 1.45)

makeArms()
rig.vmLAweld = weldParts(rig.vmLA, weaponViewModel.Base, rig.vmLA, rig.animationSet.LeftArmBase.Value)
rig.vmRAweld = weldParts(rig.vmRA, weaponViewModel.Base, rig.vmRA, rig.animationSet.RightArmBase.Value)

local weaponWorldModel = weaponId.WorldModel:Clone()
rig.wmWeapon = weaponWorldModel
weaponWorldModel.Parent = character
rig.wmBaseWeld = weldParts(weaponWorldModel.Base, weaponWorldModel.Base, character["Right Arm"])
rig.wmBaseWeld.C0 = CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0.42, weaponStats.Type == "Pistol" and 1.2 or 1.32, 0.91)
_G.HUD.updateWeaponInfo(slot.bulletsInMag, slot.bulletStorage, slot.name, slot.firingMode)

for i, v in pairs(weaponSounds) do v.destroy() end
weaponSounds = _G.Sound.uploadTable(rig.vmWeapon.Muzzle:GetChildren(), character.Torso)

rig.leftShoulder.DesiredAngle = 0
rig.rightShoulder.DesiredAngle = 0

weaponEnabled = true
end

function unequip()
if not weaponEnabled then
print("weaponEnabled == false")
return
end
if rig.vmWeapon then rig.vmWeapon:Destroy() end
if rig.wmWeapon then rig.wmWeapon:Destroy() end
rig.vmBaseWeld = nil
rig.wmBaseWeld = nil
weaponEnabled = false
aiming = false
shooting = false
local magType = weaponStats.Magazine
weaponStats = {}
for i, v in pairs(weaponSounds) do v.destroy() end
if sprinting then
Spawn(sprintOff)
end
return weaponInfo[equipped].bulletStorage, magType
end

function adjustFiringMode()
local weapon = weaponInfo[equipped]
local stats = weapon.weaponStats
weapon.firingMode = weapon.firingMode == "Auto" and "Semi" or weapon.firingMode == "Semi" and "Single" or stats.FireType

_G.HUD.updateWeaponInfo(weapon.bulletsInMag, weapon.bulletStorage, nil, weapon.firingMode)
end

function reload()
local weapon = weaponInfo[equipped]
if not weaponEnabled or not weapon or weapon.bulletStorage <= 0 or weapon.bulletsInMag == weaponStats.CapacityPerMag or reloading then return end
reloading = true
if sprinting then
sprintOff()
end
if aiming then
aimOff()
end
if shooting then
shooting = false
end
_G.Animate.runAnimation({["LeftArm"] = rig.vmLAweld}, weaponInfo[equipped].animations.Reload.Value)
_G.Animate.tweenWeld(rig.vmLAweld, 0, weaponInfo[equipped].animations.LeftArmBase.Value, 3, true)

local bulletsTaken = math.min(weaponStats.CapacityPerMag, weapon.bulletStorage)
weapon.bulletsInMag = bulletsTaken
weapon.bulletStorage = weapon.bulletStorage - bulletsTaken

_G.HUD.updateWeaponInfo(weapon.bulletsInMag, weapon.bulletStorage, nil, nil)

reloading = false
end

function shoot()
if weaponInfo[equipped].bulletsInMag <= 0 then
--play out of ammo sound
end
if not weaponEnabled or reloading or stopping or shooting or (tick() - lastFire < weaponStats.FireRate) or (weaponInfo[equipped].bulletsInMag <= 0) then return end
shooting = true
if sprinting then
sprintOff()
elseif stopping then repeat wait(0) until not stopping or sprinting end
if sprinting then
shooting = false
return
end
local weapon = weaponInfo[equipped]

local bulletsFired = 0
local semi = weapon.firingMode == "Semi"
local ads = aiming
print(ads)
repeat
ads = (ads and aiming) or false
print(ads)
lastFire = tick()

local baseShot = CFrame.new(rig.vmWeapon.Muzzle.Position) * CFrame.new(Vector3.new(), rig.vmWeapon.Muzzle.CFrame.lookVector * 1)
local distanceFromHead = (rig.vmWeapon.Muzzle.Position - character.Head.Position).magnitude
local altShot = baseShot * CFrame.new(0, 0, distanceFromHead)
local part = advHit(Ray.new(altShot.p, altShot.lookVector * distanceFromHead), {camera, character, server}, true, true)
local shootCF = part and altShot or baseShot
* CFrame.Angles(0, 0, math.random(1, 360))
* CFrame.Angles(math.rad(math.random(ads and weaponStats.MinSpreadAim or weaponStats.MinSpreadHip, ads and weaponStats.MaxSpreadAim or weaponStats.MaxSpreadHip) * 0.005 * (moving and 1.25 or 1)), 0, 0)
sendBulletRequest(shootCF)

local recoil, reduction = weaponStats.Recoil, (100 - weaponStats.RecoilReduction)/100
local baseRecoil = ((math.random(-2,2)*0.1)+ recoil) * (ads and 0.001 or 0.002) * reduction
local upwards, sway = recoil * reduction * 0.01, recoil * reduction * 0.0025 * (math.random() - .5)
recoilCam(upwards, sway, 0.03, .005, math.random() * .2 + 0.8)
weaponSounds["Fire"].play()
if weaponSounds["Fire2"] then
weaponSounds["Fire2"].play()
end
_G.Animate.recoilWeld(rig.vmBaseWeld, 0, CFrame.new(0, (recoil * 0.003), baseRecoil * 1.25) * CFrame.new(math.rad(math.random(-1, 1)),-math.rad(5),baseRecoil), 3, 6, false, CFrame.new(0,0,0))
weapon.bulletsInMag = weapon.bulletsInMag - 1
bulletsFired = bulletsFired + 1
_G.HUD.updateWeaponInfo(weapon.bulletsInMag, weapon.bulletStorage, nil, nil)
local flash = resources.MuzzleFlash:Clone()
flash.Parent = rig.wmWeapon.Muzzle
game.Debris:AddItem(flash, 0.05)
wait(weaponStats.FireRate)
until (not shooting and not semi) or (semi and bulletsFired == 3) or weapon.bulletsInMag <= 0 or not active or not weaponEnabled or weapon.firingMode == "Single"
if weapon.bulletsInMag <= 0 then reload() end
end

function aim()
if sprinting then sprintOff() end
if sprinting then return end
_G.Animate.tweenWeld(rig.vmBaseWeld, 0, CFrame.new(0, weaponStats.AimHeight, weaponStats.AimZ) or CFrame.new(0, .1, 1), 5, true)
aiming = true
end

function aimOff()
if not weaponEnabled then return end
aiming = false
tiltUp = false
_G.Animate.tweenWeld(rig.vmBaseWeld, 0, CFrame.new(.65, -.25, -1.45):inverse(), 5, true)
end

function getDrop()
local ray = Ray.new(camera.CoordinateFrame.p, camera.CoordinateFrame.lookVector * 7)
local hit = advHit(ray, {player.Character, camera, server.Effects}, false, false)
if hit and hit:IsDescendantOf(server.Drops) then
print(hit and "c2")
local part = hit
local foundDrop = false
repeat
if part.Parent == server.Drops then
foundDrop = true
return part
else
part = part.Parent
end
until foundDrop
end
end

function pickup()
if reloading then return end
local drop = getDrop()
if drop and resources.Weapons:FindFirstChild(drop.DropId.Value) then
local bullets, oldMagType = sendDropRequest()
player.Inventory.MainWeapon.Value = drop.DropId.Value
equipWeapon(1, resources.Weapons[player.Inventory.MainWeapon.Value], true, drop.Bullets.Value, bullets, oldMagType)
drop:Destroy()
wait()
if equipped == 1 and weaponInfo[1].bulletsInMag == 0 then
reload()
end
end
end

function takeAmmo()
local drop = getDrop()
if not weaponInfo[1] or (weaponInfo[1].bulletStorage >= weaponStats.CapacityPerMag * 2) then return end
if drop and resources.Weapons:FindFirstChild(drop.DropId.Value) then
if weaponInfo[1] and drop.MagazineModel.Value == weaponInfo[1].weaponStats.Magazine and drop.Bullets.Value > 0 then
local id = resources.Weapons:FindFirstChild(drop.DropId.Value)
drop.WorldModel.Magazine:Destroy()
local slot = weaponInfo[1]
slot.bulletStorage = slot.bulletStorage + drop.Bullets.Value
print(slot.bulletStorage)
drop.Bullets.Value = 0
_G.HUD.updateWeaponInfo(slot.bulletsInMag, slot.bulletStorage, slot.name, slot.firingMode)
_G.HUD.objectVisible("tooltip", false)
wait()
if slot.bulletsInMag == 0 and equipped == 1 then
reload()
end
end
end
end

function sendBulletRequest(shootCF)
local request = Instance.new("Configuration")
request.Name = "Bullet"
createValue("ObjectValue", request, "Player", player)
createValue("ObjectValue", request, "Character", character)
createValue("CFrameValue", request, "Origin", shootCF)
createValue("IntValue", request, "Damage", weaponStats.Damage)
createValue("StringValue", request, "Special", weaponStats.Special)
createValue("NumberValue", request, "MuzzleVelocity", weaponStats.MuzzleVelocity)
--add more things when needed
request.Parent = server.Requests
end

function sendDropRequest()
local oldWeapon = player.Inventory.MainWeapon.Value
if oldWeapon == "" then return end
player.Inventory.MainWeapon.Value = ""
local request = Instance.new("Configuration")
request.Name = "Drop"
createValue("StringValue", request, "WeaponId", oldWeapon)
createValue("StringValue", request, "WeaponName", weaponInfo[1].name)

local hit, pos = advHit(Ray.new(torso.Position, Vector3.new(-2.5, 0, 2.5)), {character, workspace.Camera, server.Effects}, true, false)
createValue("Vector3Value", request, "Position", pos + Vector3.new(0, 0.5, 0))

createValue("IntValue", request, "Bullets", weaponInfo[1].bulletsInMag)

local bullets, magType = unequip()
request.Parent = server.Requests
return bullets, magType
end

function disableDefault()
character.Humanoid.PlatformStand = true
waitForObjects(character, "Animate", "Sound")
destroy(character, "Animate", "Sound")
end

function addFirstPersonObjects()
rig.viewModel = Instance.new("Model", camera)
rig.viewModel.Name = "ViewModel"
local base = Instance.new("Part", rig.viewModel)
base.CanCollide = false
base.FormFactor = Enum.FormFactor.Custom
base.Size = Vector3.new(0.2, 0.2, 0.2)
base.Transparency = 1
rig.viewBase = base
local baseWeld = Instance.new("Weld", base)
baseWeld.Part0 = character.Head
baseWeld.Part1 = base
rig.baseWeld = baseWeld
end

function addMovementObjects()
rig.fakeTorso = torso:Clone()
rig.fakeTorso.Name = "FakeTorso"
rig.fakeTorso.Parent = character
rig.torsoWeld = weldParts(torso, torso, rig.fakeTorso)
movementSounds = _G.Sound.uploadTable(resources.Sounds.Movement:GetChildren(), character.Torso)
objects.bVelo = Instance.new("BodyVelocity", torso)
objects.bVelo.maxForce = Vector3.new()
objects.bGyro = Instance.new("BodyGyro", torso)
objects.bGyro.maxTorque = Vector3.new(20000, 20000, 20000)
objects.bGyro.P = 14000
objects.bGyro.D = 800
objects.bPos = Instance.new("BodyPosition")
objects.bPos.position = torso.Position
objects.bPos.D = 2000000
objects.bPos.P = 300000000
objects.bPos.Parent = torso
rig.leftHip = torso["Left Hip"]
rig.rightHip = torso["Right Hip"]
rig.leftShoulder = torso["Left Shoulder"]
rig.rightShoulder = torso["Right Shoulder"]

rig.leftHip.Part0 = rig.fakeTorso
rig.rightHip.Part0 = rig.fakeTorso
rig.leftShoulder.Part0 = rig.fakeTorso
rig.rightShoulder.Part0 = rig.fakeTorso

rig.leftShoulder.C1 = CFrame.new(0.5, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
rig.rightShoulder.C1 = CFrame.new(-0.5, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
rig.leftShoulder.DesiredAngle = 0
rig.rightShoulder.DesiredAngle = 0

torso.Transparency = 1
torso.CanCollide = false
end

function createNeck()
local fakeHead = character.Head:Clone()
fakeHead.Parent = character
fakeHead.Name = "FakeHead"
fakeHead.CanCollide = false
fakeHead.Size = Vector3.new(1, 1, 1)
rig.fakeHead = fakeHead
character.Head.Transparency = 1
character.Head:ClearAllChildren()
local neck = Instance.new("Weld", fakeHead)
neck.Part0 = character.Head
neck.Part1 = fakeHead
neck.C0 = CFrame.new(0, -0.75, 0)
rig.neck = neck
torso.Neck.C0 = torso.Neck.C0 --* CFrame.Angles(0, 0, math.rad(45))
end

local eDown = false

function bindKeys()
for i, v in pairs(bindings) do
events[#events + 1] = mouse.KeyDown:connect(function(key)
if key == i then
movement[v] = true
if v == "jump" then
crouchOff()
end
end
end)
events[#events + 1] = mouse.KeyUp:connect(function(key)
if key == i then
movement[v] = false
end
end)
end
events[#events + 1] = mouse.KeyDown:connect(function(key)
if key == "0" then
sprintOn()
elseif key == "2" then
if movement.crouch then
crouchOff()
else
crouchOn()
end
end
end)
events[#events + 1] = mouse.KeyUp:connect(function(key)
if key == "0" then
sprintOff()
elseif key == "2" then
crouchOff()
elseif key == "c" then
tiltUp = false
elseif key == "e" then
if tick() - eDown < 0.7 then
takeAmmo()
end
eDown = tick()
end
end)
events[#events + 1] = mouse.Button1Down:connect(function()
print("haha")
shoot()
end)
events[#events + 1] = mouse.Button1Up:connect(function()
shooting = false
end)
events[#events + 1] = mouse.Button2Down:connect(function()
aim()
end)
events[#events + 1] = mouse.Button2Up:connect(function()
aimOff()
end)
events[#events + 1] = mouse.KeyDown:connect(function(key)
if key == "e" then
eDown = tick()
local v = eDown
delay(.3, function()
if eDown == v then
pickup()
end
end)
elseif key == "g" then
--swap()
elseif key == "r" then
reload()
elseif key == "c" then
tiltUp = true
elseif key == "f" then
adjustFiringMode()
end
end)
events[#events + 1] = mouse.WheelForward:connect(function()
if aiming and tiltUp then
zeroValue = math.min((zeroValue + 0.2), 2)
else
switchWeapon(equipped%#weaponInfo + 1)
end
end)
events[#events + 1] = mouse.WheelBackward:connect(function()
if aiming and tiltUp then
zeroValue = math.max((zeroValue - 0.2), 0)
else
switchWeapon((equipped - 2)%#weaponInfo + 1)
end
end)
end

--// Update Functions

function updateMovement()
if not torso then active = false return end
local look = camera.CoordinateFrame
local moveVector = getMovementVector(look)
local touchingFloor, floorPos = findFloor(moveVector)
local cfYaw = CFrame.new(Vector3.new(), getYaw(look))
local pitch = getPitch(look)
sprinting = movement.forward and movement.sprint and moving and not velocity and not stunned and touchingFloor
local crouching = movement.crouch

lastLanding = inAir and touchingFloor and tick() or lastLanding
inAir = not touchingFloor
canJump = tick() - lastLanding > 0.4
torsoAngle = (torsoAngle * 3 + ((sprinting or not weaponEnabled) and 0 or 45))/4
height = (height * 3 + (crouching and 2 or 3))/4

local jumping = touchingFloor and movement.jump and canJump
velocity = touchingFloor and touchingFloor.Velocity.magnitude > 0.1

objects.bVelo.maxForce = touchingFloor and (jumping and Vector3.new(0, 999999, 0) or Vector3.new(12000, 12000, 12000)) or Vector3.new(750, 0, 750)
objects.bVelo.velocity = jumping and Vector3.new(0, 40, 0) or (moveVector * (stunned and 0.5 or 1) * ((aiming or crouching) and 12 or sprinting and 24 or runSpeed)) + (touchingFloor and touchingFloor.Velocity or Vector3.new())

objects.bPos.position = floorPos * Vector3.new(0,1,0) + Vector3.new(0, height, 0)
objects.bPos.maxForce = touchingFloor and Vector3.new(0,40000,0) or Vector3.new()
objects.bGyro.cframe = CFrame.new(torso.Position) * cfYaw --* CFrame.Angles(0, -math.rad(torsoAngle), 0)

-- torso.CFrame = CFrame.new(torso.Position) * cfYaw --* CFrame.Angles(0, -math.rad(torsoAngle), 0)

pitch = (pitch + math.pi) % (math.pi * 2)
pitch = constrain(pitch, 2, 4.2) - math.pi
local neckPitch = constrain(pitch, -696969, 0.47)
neckRoll = (neckRoll * 2 + (aiming and pitch < 0.47 and 17.5 or 0)) / 3

rig.neck.C1 = CFrame.new(0, -0.75, 0) * CFrame.Angles(0, 0, math.rad(neckRoll)) * CFrame.Angles(-neckPitch, 0, 0)
torso.Neck.C0 = nC0 --* CFrame.Angles(0, 0, math.rad(torsoAngle))
rig.torsoWeld.C1 = CFrame.Angles(0, math.rad(torsoAngle), 0)

armPitch = (sprinting and (armPitch * 9 + math.rad(-45))/10) or pitch

if touchingFloor and moving and time() - lastStep > (sprinting and 0.2 or (aiming or crouching) and 0.4 or 0.3) then
lastStep = time()
local minimum, maximum = sprinting and 18 or (aiming or crouching) and 12 or 13, sprinting and 23 or (aiming or crouching) and 15 or 16
movementSounds.Run.play(math.random(minimum, maximum) * 0.1)
end

if jumping then
movementSounds.Jump.play(math.random(8, 18) * 0.1)
end

local limbAngle = math.rad(math.sin(time() * 10) * 30 * moveVector.magnitude)
rig.leftHip.DesiredAngle = limbAngle
rig.rightHip.DesiredAngle = limbAngle

if crouching then --0.75
rig.leftHip.C0 = (weaponEnabled and lhC0alt or lhC0) * CFrame.new(-0.55, 0.6, 0) * CFrame.Angles(0, 0, math.rad(17))
rig.rightHip.C0 = (weaponEnabled and rhC0alt or rhC0) * CFrame.new(0.55, 0.6, 0) * CFrame.Angles(0, 0, math.rad(-17))
else
if weaponEnabled then
rig.leftHip.C0 = lhC0alt * CFrame.new(0.09, 0.02, -0.01)
rig.rightHip.C0 = rhC0alt * CFrame.new(-0.01, 0, 0)
else
rig.leftHip.C0 = lhC0
rig.rightHip.C0 = rhC0
rig.leftShoulder.DesiredAngle = -limbAngle
rig.rightShoulder.DesiredAngle = -limbAngle
end
end
rig.leftShoulder.C0 = weaponEnabled and laC0 * CFrame.new(-.5,0,-.7) * CFrame.Angles(0, math.rad(armYaw), -(armPitch + math.rad(90))) or laC0
rig.rightShoulder.C0 = weaponEnabled and raC0 * CFrame.Angles(0, math.rad(45) , (armPitch + math.rad(90))) or raC0
end

function updateFirstPerson(change)
if change == "FieldOfView" then return end
local look = camera.CoordinateFrame.lookVector
local rise, run = look.y, -math.sqrt(look.x*look.x + look.z*look.z)
local pitchVector = Vector3.new(0, rise, run).unit
local yawVector = getYaw(camera.CoordinateFrame)

verGoal = shooting and 0 or math.sin(tick() * (moving and runSpeed * 0.55 * (stunned and 0.2 or 1) or 1)) * (moving and 0.02 or 0.01) / ((aiming and not moving and 4) or aiming and 1.5 or 1)
verGoal = moving and math.abs(verGoal) or verGoal
horGoal = shooting and 0 or math.cos(tick() * (moving and runSpeed * 0.75 * (stunned and 0.2 or 1) or 1)) * (moving and 0.02 or 0.01) / ((aiming and not moving and 4) or aiming and 1.5 or 1)
verCur, horCur = verCur - (verCur - verGoal)*0.5, horCur - (horCur - horGoal)*0.5
zIn = (zIn * 2 + (movement.crouch and 0.15 or 0))/3

local pitch, yaw = math.atan2(rise, run), math.atan2(yawVector.x, yawVector.z)
local pitchChange = lastPitch - pitch
local yawChange = lastYaw - yaw
local strafe = math.rad(((movement.left and 1 or 0) - (movement.right and 1 or 0)) * 2.5)
pitchChange = pitchChange * (math.abs(pitchChange) < .7 and 1 or 0)
yawChange = yawChange * (math.abs(yawChange) < .7 and 1 or 0)
xTilt = (xTilt * 5 + pitchChange * 6)/6
yTilt = (yTilt * 5 + (sprinting and 0 or yawChange) * 6)/6
zTilt = (zTilt * 5 + (sprinting and 0 or strafe)) / 6

tiltValue = (tiltValue * 2 + ((tiltUp and aiming and weaponStats.Type == "Rifle") and zeroValue or 0)) / 3

rig.baseWeld.C0 = CFrame.new(Vector3.new(), pitchVector) * CFrame.Angles(xTilt * math.rad(-8), yTilt * math.rad(8), yTilt * math.rad(-8))
* CFrame.new(horCur * 2, verCur * 2, zIn) * CFrame.Angles(math.rad(tiltValue), 0, 0)

camera.FieldOfView = constrain((camera.FieldOfView * 2 + (aiming and 40 or 70)) / 3, 20, 80)
lastPitch, lastYaw = pitch, yaw
end

function setupRig()
waitForObjects(character, "Head", "Torso", "Left Leg", "Right Leg", "Left Arm", "Right Arm", "Humanoid")
torso = character.Torso
local controls = game:GetService("ControllerService"):GetChildren()[1]
if controls then controls.Parent = nil end
waitForObjects(torso, "Left Shoulder", "Right Shoulder", "Left Hip", "Right Hip", "Neck")
wait(0)
disableDefault()
addMovementObjects()
createNeck()
addFirstPersonObjects()
bindKeys()
findChild = character.FindFirstChild
end

gFunctions.getAmmoType = function()
if weaponInfo[1] and weaponInfo[1].weaponStats and weaponInfo[1].weaponStats.Magazine then
return weaponInfo[1].weaponStats.Magazine
else
return nil --oh yeah
end
end

gFunctions.getWeaponInfo = function()
if equipped then
local weapon = weaponInfo[equipped]
return weapon.bulletsInMag, weapon.bulletStorage, weapon.name, weapon.firingMode, weapon.weaponStats.CapacityPerMag
end
end

gFunctions.stun = function(duration)
stunned = true
-- recoilCam(math.rad(math.random(10, 25)), math.rad(math.random(-5, 5)), 0.1, 0, 0)
wait(duration)
stunned = false
end

gFunctions.activate = function()
if not player.Character then player.CharacterAdded:wait() end
print("initializing")
character = player.Character
setupRig()
player.CameraMode = 1
active = true

events[#events + 1] = camera.Changed:connect(updateMovement)
events[#events + 1] = camera.Changed:connect(updateFirstPerson)
events[#events + 1] = player.Chatted:connect(function()
for i, v in pairs(movement) do
movement[i] = false
end
aimOff()
shooting = false
end)
equipWeapon(2, resources.Weapons.Pistol)
if resources.Weapons:FindFirstChild(player.Inventory.MainWeapon.Value) then
equipWeapon(1, resources.Weapons[player.Inventory.MainWeapon.Value])
end
Spawn(function()
local stepped = game:GetService("RunService").Stepped
repeat
updateMovement()
updateFirstPerson()
stepped:wait()
until not active
end)
end

gFunctions.deactivate = function(dropWeapon)
if dropWeapon then
pcall(sendDropRequest)
end
if character:FindFirstChild("Head") and character:FindFirstChild("FakeHead") then
for _, obj in pairs(character.FakeHead:GetChildren()) do
obj.Parent = character.Head
end
character.Head.Transparency = 0
end
active = false
weaponEnabled = false
weaponStats = {}
weaponInfo = {}
equipped = nil
for i, v in pairs(events) do
v:disconnect()
end
for i, v in pairs(movement) do
movement[i] = false
end
camera:ClearAllChildren()
events = {}

weaponEnabled = false
shooting = false
aiming = false
reloading = false
moving = false
sprinting = false
stunned = false
stopping = false

if torso then
destroy(torso, "BodyPosition", "BodyVelocity", "BodyGyro")
end
end

gFunctions.ready = true
Report Abuse
DarkComa is not online. DarkComa
Joined: 01 Apr 2011
Total Posts: 11679
01 Oct 2014 11:28 AM
idiot that sends u to purgatory

what were you tryin to do!!!!!!!
Report Abuse
PoisonBreeze is not online. PoisonBreeze
Joined: 05 Sep 2008
Total Posts: 3116
01 Oct 2014 11:31 AM
Have you tried scripting helpers?

'That is as pointless as a blunt pencil.'
Report Abuse
OnEnter is not online. OnEnter
Joined: 10 Jun 2008
Total Posts: 372
01 Oct 2014 11:31 AM
local player means u can access ur local shops n stuff
Report Abuse
cooldudexd10 is not online. cooldudexd10
Joined: 27 May 2012
Total Posts: 17159
01 Oct 2014 11:33 AM
Ever heard of the thing "google"
Report Abuse
DarkComa is not online. DarkComa
Joined: 01 Apr 2011
Total Posts: 11679
01 Oct 2014 11:36 AM
@cooldudexd10

dont u mean goggl?
Report Abuse
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:42 AM
you guys are no help. like asking a bunch of five year olds a complex equation
Report Abuse
firelenny123 is not online. firelenny123
Joined: 29 Sep 2014
Total Posts: 315
01 Oct 2014 11:47 AM
because you're trying to use localplayer in a normal script
localplayer = localscript
Report Abuse
CDDoggGaming is not online. CDDoggGaming
Joined: 10 Aug 2010
Total Posts: 960
01 Oct 2014 11:49 AM
it doesnt work as a local script either but thank you for at least trying to help.
Report Abuse
DarkComa is not online. DarkComa
Joined: 01 Apr 2011
Total Posts: 11679
01 Oct 2014 11:56 AM
"you guys are no help. like asking a bunch of five year olds a complex equation"

hahaha
scrub
Report Abuse
CasualtiesOccured is not online. CasualtiesOccured
Joined: 26 May 2014
Total Posts: 2530
01 Oct 2014 12:14 PM
for the love of god.
make a localscript
add wait() to the top

now calm the hell down.

localplayer = a special event that is only access via a local script.

basically all it means is the player the script is inside of.
Report Abuse
DeviousDeviation is not online. DeviousDeviation
Joined: 28 Dec 2010
Total Posts: 9306
01 Oct 2014 12:18 PM
used in localscripts to get the client's player

guise i have a siggy
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Roblox » All Things ROBLOX
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image