|
| 06 Dec 2015 07:18 PM |
This happens quite alot with me, and while most of the time it isn't anything game-breaking, this time it is. One of the main functions of my mortar is that if you are crouching it won't shoot, and I've gotten to the point where it works in studio perfectly, but in Public you can't even crouch. Here is the code:
on = false RELOAD_TIME = 10
local body = script.Parent.Parent.Parent.Character local mortar = script.Parent local RJ = body.HumanoidRootPart local humanoid = script.Parent.Parent.Parent.Character.Humanoid local ShouldShoot = script.Parent:WaitForChild("ShouldShoot")
function crouch(key) if key then key = string.lower(key) if (key=="c") or (key=="q") then if on == false then print("Crouched") body.Torso["Right Hip"].C0 = CFrame.new(.5, -1, -.5) body.Torso["Right Hip"].C1 = CFrame.Angles(0, 0, 0) body.Torso["Left Hip"].C0 = CFrame.new(-.5, -1, -.5) body.Torso["Left Hip"].C1 = CFrame.Angles(0, 0, 0) RJ.RootJoint.C0 = CFrame.new(0, -1.25, 0) * CFrame.Angles(0, 0, 0) RJ.RootJoint.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
humanoid.WalkSpeed = 0
mortar.ShouldShoot.Value = true on = true else if on == true then print("Uncrouched") body.Torso["Right Hip"].C0 = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0) body.Torso["Right Hip"].C1 = CFrame.Angles(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0) body.Torso["Left Hip"].C0 = CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0) body.Torso["Left Hip"].C1 = CFrame.Angles(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0) RJ.RootJoint.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0) RJ.RootJoint.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
humanoid.WalkSpeed = 16
mortar.ShouldShoot.Value = false
on = false
end end end end end function Equip(mouse) mouse.KeyDown:connect(crouch) end script.Parent.Equipped:connect(Equip)
Are there any glaring problems with it? It's in a Script, not a LocalScript, if that matters. It's in a Tool. |
|
|
| Report Abuse |
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 06 Dec 2015 07:42 PM |
| Wait for the humanoid, as it might take some time to load. |
|
|
| Report Abuse |
|
|
| 06 Dec 2015 08:53 PM |
| No luck. I started a server in Studio on the Test tab, and it's not working there either, and it's not giving any errors. |
|
|
| Report Abuse |
|
|
| 06 Dec 2015 09:12 PM |
Alright, I don't know what I did but it's showing errors now, specifically:
19:06:34.907 - Players.Player1.Backpack.MORTAR.Crouch2:6: attempt to index local 'body' (a nil value) 19:06:34.908 - Stack Begin 19:06:34.908 - Script 'Players.Player1.Backpack.MORTAR.Crouch2', Line 6 19:06:34.908 - Stack End
When here, it quite obviously defines "body":
local body = script.Parent.Parent.Parent.Character local mortar = script.Parent local RJ = body.HumanoidRootPart local humanoid = script.Parent.Parent.Parent.Character.Humanoid local ShouldShoot = script.Parent:WaitForChild("ShouldShoot")
I tried :WaitForChild("Character") and it didn't work even in solo mode. I put a break on it, and it gets to that point of the script, but it doesn't get past it. |
|
|
| Report Abuse |
|
Tarkol
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 425 |
|
|
| 06 Dec 2015 09:54 PM |
Can you post the whole crouch script? From what you've posted, my guess is to change the "body" from a local variable to a global (delete "local") but I'm not sure if that's your issue.
~Praise the Sun~ |
|
|
| Report Abuse |
|
Tarkol
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 425 |
|
|
| 06 Dec 2015 10:11 PM |
My bad, I didn't read the whole post...
~Praise the Sun~ |
|
|
| Report Abuse |
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 07 Dec 2015 11:34 AM |
| Where is this script located in? |
|
|
| Report Abuse |
|
|
| 07 Dec 2015 12:12 PM |
| It takes time for the character to load. |
|
|
| Report Abuse |
|
iMung
|
  |
| Joined: 11 Jul 2013 |
| Total Posts: 328 |
|
|
| 07 Dec 2015 01:49 PM |
| It is a ROBLOX bug which happens in solo. It works in solo, but not in a server/game. Just rescript it, and make sure you read it over a couple of times. A good trick to debugging code is printing. Example: function kill() print(1) if a == 1 then print(2) if b == 2 then print(3) end end end You use it to find where the script got to. |
|
|
| Report Abuse |
|
iMung
|
  |
| Joined: 11 Jul 2013 |
| Total Posts: 328 |
|
|
| 07 Dec 2015 01:50 PM |
| Make sure it is a local script. You can only do game.Players.LocalPlayer in localscripts. |
|
|
| Report Abuse |
|