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

I cant stop my animation from playing. Any help?

Whenever I equip my weapon, an animation plays. here is my "SERVER" script for later references:

script.Parent.nowits6rlly.OnServerEvent:Connect(function(Player, State)
	local animation = script.Parent:WaitForChild('On')
	local humanoid = Player.Character:WaitForChild("Humanoid")
	local On = humanoid:LoadAnimation(animation)
	if State == "On" then
		On:Play()
		On.Looped = true
	elseif State == "Off" then
		On:Stop()
		On.Looped = false
	end
end)
script.Parent.RayCastEvent.OnServerEvent:Connect(function(Player)
	local animation = script.Parent:WaitForChild('Shoot')
	local humanoid = Player.Character:WaitForChild("Humanoid")
	local Shoot = humanoid:LoadAnimation(animation)
	Shoot:Play()
end)
script.Parent.RELOAD.OnServerEvent:Connect(function(Player)
	local animation = script.Parent:WaitForChild('Reload')
	local humanoid = Player.Character:WaitForChild("Humanoid")
	local Reload = humanoid:LoadAnimation(animation)
	Reload.Looped = false
	Reload:Play()
end)

The script works until I unequip it, when it gives me the error. Here is the "LOCAL" script that sends the function when I unequip:

script.Parent.Unequipped:Connect(function()
	Mouse.Icon = "rbxasset://SystemCursors/Arrow"
	AnimationStatus = "Off"
	script.Parent.nowits6rlly:FireServer(AnimationStatus)
end)

EDIT: The error is gone, but the animation still wont stop. EDIT: I made a typo and fixed it by saying local script and not script.

9 comments

0

It means the variable LocalPlayer is nil

0

I know but i dont know why LocalPlayer sets to nil after unequipping

0

just change LocalPlayer to Player, you don't need that 3rd argument, it only opens your code for exploiters

0

oh thx

0

good news! no more error, but now the animation just wont stop.

0

Did you mean On.Looped = false at line 10? Make sure it's . not :

0

Pupppy44's method did not work.

0

Use Animation:Stop()

0

Already solved it

1 answer

✓ Accepted answer

You are using OnServerEvent in a local based script. (line 1 of your first script)

You are also using FireServer in the other script (line 4)

Whenever loading an animation onto a user (must be a valid user of roblox, not an npc) you use a local script to load, play, and stop animations. If the character is an npc you use a server script. The unequipped function should be combined into the larger script.

OnServerEvent only works for the server, not the client. You cannot fire a remote event to the server, its remote. If you want to do server to server or client to client use bindable events (Read up on them here)

Basically you have to convert a lot of this to local scripts and make it fe (filtering enabled) compatible.

Info on remote events: link

Info on RemoteEvent#FireServer: link

Info on RemoteEvent#OnServerEvent: link

Info on RemoteEvent#FireClient: link

Info on RemoteEvent#OnClientEvent: link

Info on BindableEvents: link

Info on BindableEvents#Fire: link

Info on BindableEvents#Event: link

I hope these dev resources help out too!

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