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

The roblox animation I made does not run in the Studio or in game, why?

I have made a tool with a localscript and an animation in it, that when the tool is activated it should fire a remote event, increase their strength by one and play an animation.

Tool localscript:

local anim = script.Animation
local char = game.Player.LocalPlayer.Character:Wait()

script.Parent.Activated:Connect(function()
	local humanoid = char:WaitForChild("Humanoid")
	local trackanim = humanoid:LoadAnimation(anim)
	trackanim:Play()
	
	workspace.Event.StrengthEvent:FireServer()
	script.Parent.Enabled = true
	wait(1)
	script.Parent.Enabled = false
end)

Event (Script in workspace in which is StrengthEvent):

script.StrengthEvent.OnServerEvent:Connect(function(player)
	player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1
end)

The value will not increase and the animation will not play. And yes the animation priority is set to action Please help (if there is an error I'm still a beginner please help me point it out.)

5 comments

0

Any errors?

0

I do not know

0

how do you not know, you have your output open dont you?

0

Only errors from other scripts

0

But it does say 20:55:33.708 - Unable to load rbxasset://avatar/characterR15V3.rbxm

2 answers

Make sure the animation's priority is set to action.

1 comment

0

It is set to action

Two problems. First game.Player.LocalPlayer.Character:Wait() is not a proper usage. Second animation loading should be done only once, preferably outside of your function.

local anim = script.Animation
local char = game.Player.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")
humanoid:WaitForChild("Animator") -- paranoid precaution I like to use - without it sometimes animation will not replicate properly to other players
local trackanim = humanoid:LoadAnimation(anim)

local debounce = false
script.Parent.Activated:Connect(function()
    
    if debounce then return end
    debounce = true
    
    trackanim:Play()

    workspace.Event.StrengthEvent:FireServer()

	--dont use these, use debounce
    --[[script.Parent.Enabled = true
    wait(1)
    script.Parent.Enabled = false--]]
    wait(1)
    debounce = false
end)

Hope this helps!

EDIT: I noticed your event is in the workspace. I do not know if that would work, all remote events should be in the Replicated Storage!

EDIT 2: Fix for RemoteEvent

Put your Event folder in ReplicatedStorage

Server Script:

local StrengthEvent = game.ReplicatedStorage.Event.StrengthEvent
StrengthEvent.OnServerEvent:Connect(function(player)
    player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1
end)

Local Script

local anim = script.Animation
local char = game.Player.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")
humanoid:WaitForChild("Animator") -- paranoid precaution I like to use - without it sometimes animation will not replicate properly to other players
local trackanim = humanoid:LoadAnimation(anim)

local eventFolder = game.ReplicatedStorage:WaitForChild("Event")
local StrengthEvent = eventFolder:WaitForChild("StrengthEvent")

local debounce = false
script.Parent.Activated:Connect(function()
    
    if debounce then return end
    debounce = true
    
    trackanim:Play()

    StrengthEvent:FireServer()

	--dont use these, use debounce
    --[[script.Parent.Enabled = true
    wait(1)
    script.Parent.Enabled = false--]]
    wait(1)
    debounce = false
end)

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