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

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

Asked by 3 years ago
Edited 3 years ago

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.)

0
Any errors? zadobyte 692 — 3y
0
I do not know NathanBlox_Studios 212 — 3y
0
how do you not know, you have your output open dont you? zadobyte 692 — 3y
0
Only errors from other scripts NathanBlox_Studios 212 — 3y
0
But it does say 20:55:33.708 - Unable to load rbxasset://avatar/characterR15V3.rbxm NathanBlox_Studios 212 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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

0
It is set to action NathanBlox_Studios 212 — 3y
Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
3 years ago
Edited 3 years ago

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)

Answer this question