Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my script work fine in studio, but does not work at all in the actual game?

Asked by 5 years ago

Hello! Hope you are all fine :P Well the problem is that with the (local) script below, is that it works perfectly in studio, but it doesn't work at all in game.. Can anyone help ;-;

Yes its all the script and anyone can copy it but whatever Ooof


local player = game.Players.LocalPlayer local desaa = false local debounce = true local punch = true local ipit = game:GetService("UserInputService") local char = game.Workspace:WaitForChild(player.Name) local arm = char.RightHand local punchanimation = Instance.new("Animation") punchanimation.AnimationId = "http://www.roblox.com/Asset?ID=2837641618" local kickanimation = Instance.new("Animation") kickanimation.AnimationId = "http://www.roblox.com/Asset?ID=2796826423" Instance.new("RemoteEvent",game.ServerScriptService) ipit.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 and desaa == false then local animtype = math.random(1,2) print(animtype) desaa = true debounce = false if animtype == 1 then local fadfa = char.Humanoid:LoadAnimation(punchanimation) arm.Parent = char.RightLowerArm fadfa:Play() end if animtype == 2 then local fadfa = char.Humanoid:LoadAnimation(kickanimation) arm.Parent = char.LeftFoot fadfa:Play() wait(1) fadfa:Stop() end char.Humanoid.WalkSpeed = 0 wait() wait(0.3) debounce = true wait(.9) char.Humanoid.WalkSpeed = 14 debounce = true desaa = false arm.Parent = char end end) arm.Touched:Connect(function(part) local pdafjpas = part.Parent:FindFirstChild("Humanoid",3) if punch == true and debounce == false and part.Parent:FindFirstChild("Humanoid",3)then pdafjpas.Health = pdafjpas.Health - 5 punch = false punch = true arm.Parent = char.RightLowerArm arm.Parent = char end end)
0
bc that's just Studio: some stuff only works in-game DeceptiveCaster 3761 — 5y
0
Can yah reccomend meh a way to fix it :thinking: ScriptingNubs 55 — 5y
0
It is probably due to character loading longer (arm may not exist) . Just add longer (like wait(10)) on line 18 and see if it works. If it does, find a better solution like player.CharacterAdded sleazel 1287 — 5y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago

Try changing line 07:

local arm = char.RightHand

to:

local arm = char:WaitForChild("RightHand")

as right arm may not have loaded yet.

Ad

Answer this question