Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

bc that's just Studio: some stuff only works in-game

0

Can yah reccomend meh a way to fix it :thinking:

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

1 answer

Try changing line 07:

local arm = char.RightHand

to:

local arm = char:WaitForChild("RightHand")

as right arm may not have loaded yet.

This discussion is preserved as it was. New answers, comments, and votes are closed.