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