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

why is my filtering enabled tool not playing animations?

Asked by
wookey12 174
6 years ago
Edited 6 years ago

i have a simple bat that strikes (plays an animation) when clicked, but does not work

localscript:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local bat = script.Parent

bat.Activated:Connect(function()
        local Animation = Instance.new("Animation", plr.Character)
    Animation.AnimationId = "rbxassetid://01575838216"
    local animtrack = plr.Character.Humanoid:LoadAnimation(Animation)
    bat.Strike:FireServer(plr, animtrack)
end)

serverscript:

local bat = script.Parent

bat.Strike.OnServerEvent:Connect(function(plr,animtrack)

    animtrack:Play()
end)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hi wookey12,

I think your problem is that you've put the ServerScript and the Remote Event in the wrong place. The RemoteEvent needs to be under ReplicatedStorage and the ServerScript should ideally be under ServerScriptService. Try adjusting your script to those positions and comment below if it worked. Also, I just realized something about a line in your script. The :FireServer() line already passes an argument of player inside so you don't need to put that in the parameters. Just put animtrack in those parameters, but, remember when you're doing .OnServerEvent() the first parameter will be the player always and the second parameter is whatever you pass through :FireServer(). Check here for more details on what each function/event's parameters are for RemoteEvents.

Thanks,

Best regards,

~~ KingLoneCat

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Get rid of plr in the line: bat.Strike:FireServer(plr, animtrack)

When sending a server event it automatically sends plr with it, which means you only need to have plr in the event receiving it. If you keep "plr" there it will detect the animation track as the plr.

Event sent(plr, animtrack)

Receiving(plr, plr, animtrack)

Because it auto-sends plr with it, it will be like the above. Which means,

plr = plr

animtrack = plr

And the animtrack will not be identified as a variable.

Which also means your int value will be identified as a reference to the local player.

Answer this question