Hi, I want to make a ball that upon touch is transferred to another player, hence the original player will lose the ball from it’s inventory and the player that touched it will keep the ball.
I’ve made the ball and animation work, but I cannot seem to stop the animation on the original player after the ball is transferred to someone else
I’ve made use of a bindable event (named StopAnimation) that gets fired every time the ball is touched, and thus transferred to someone else. Via a Serverscript I then try to stop the animation by doing animationtrack:Stop(). But this doesn’t seem to do the trick.
Here’s the code to transfer the ball and fire the bindeable event upon touch:
local tool = script.Parent --Tool variable
local debounce = true --Debounce (to make only 1 touch each 5 seconds)
local stopanimation = game:GetService("ReplicatedStorage"):WaitForChild("StopAnimation")
tool.Handle.Touched:Connect(function(Hand)
if Hand.Parent:FindFirstChild("Humanoid") and debounce then
debounce = false
local humanoid = tool.Parent:FindFirstChild("Humanoid") -- check if it's a player by checking if it has a humanoid
local Animation = script.Parent:FindFirstChild("Animation")
local animationtrack = humanoid:LoadAnimation(Animation)
if humanoid then
tool.Parent = Hand.Parent
stopanimation:Fire(humanoid,Animation)
end
wait(5)
debounce = true
end
end)
Here’s the code to play the animation when the ball is equipped:
local tool = script.Parent
local Animation = script.Parent:FindFirstChild("Animation")
tool.Equipped:Connect(function()
local character = tool.Parent
local humanoid = character.Humanoid
local animationtrack = humanoid:LoadAnimation(Animation)
animationtrack:Play()
end)
And finally here is the serverscript to stop the animation:
local stopanimation = game:GetService("ReplicatedStorage"):WaitForChild("StopAnimation")
stopanimation.Event:Connect(function(humanoid,animation)
print("stopanimation fired")
local animationtrack = humanoid:LoadAnimation(animation)
animationtrack:Stop()
end)
I am very new to scripting and any help, tutorial suggestions or feedback would therefor be greatly appreciated.
I’ll leave the tool I’ve made here: Ball animation test.rbxm (4.5 KB)
Thanks in advance!