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

I cant stop my animation from playing. Any help?

Asked by 4 years ago
Edited 4 years ago

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.

0
It means the variable `LocalPlayer` is nil Leamir 3138 — 4y
0
I know but i dont know why LocalPlayer sets to nil after unequipping rookiecookie153 53 — 4y
0
just change `LocalPlayer` to `Player`, you don't need that 3rd argument, it only opens your code for exploiters Leamir 3138 — 4y
0
oh thx rookiecookie153 53 — 4y
View all comments (5 more)
0
good news! no more error, but now the animation just wont stop. rookiecookie153 53 — 4y
0
Did you mean On.Looped = false at line 10? Make sure it's . not : Pupppy44 671 — 4y
0
Pupppy44's method did not work. rookiecookie153 53 — 4y
0
Use Animation:Stop() Shounak123 461 — 4y
0
Already solved it rookiecookie153 53 — 4y

1 answer

Log in to vote
0
Answered by
DollorLua 235 Moderation Voter
4 years ago

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!

Ad

Answer this question