alright i think i understand you now!
you basically want to give the player currently holding the ball a speed of 30
and whenever he gets that ball taken away you want to give him 5 seconds of that speed and then set it to default right?
well there is a key issue here, you’re changing the parent of the tool so it doesn’t affect the player that we intended to affect
to fix this we need a third party with the use of a bindable event
so first things first go to replicated storage and press right click and press “Insert Object”
and search for “BindableEvent”
call it “DelayWalkspeed” because that’s how i named it, if you want to change it you’re going to have to change it in all the scripts that i will show later on
and now we want to create a script that will react to the bindable event so go to ServerScriptService, right click and insert a script
you can name it whatever you want, it doesn’t matter!
so in your script called… Script we don’t want the unequipped event listener because we don’t want to set the walkspeed as soon as it’s unequipped, so we remove it
that’s how it should look like:
local tool = script.Parent
local speed = 30
tool.Equipped:Connect(function()
local player = game.Players:FindFirstChild(tool.Parent.Name)
if player then
player.Character.Humanoid.WalkSpeed = speed
end
end)
and now moving on to the Giveaway script
we want to detect if a player has touched the ball if he did then set the parent to the player
and when we do that we also involve the third party who will handle the walkspeed
how do we involve the third party? bindable events can be fired and used to receive data. we specifically used a bindable event because the communication is from server to server.
so the giveaway script should look like something like this:
local tool = script.Parent --Tool variable
local debounce = true
local delayWalkspeed = game:GetService("ReplicatedStorage"):WaitForChild("DelayWalkspeed") -- get the bindable event
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
if humanoid then
tool.Parent = Hand.Parent
delayWalkspeed:Fire(humanoid.Parent) -- pass the character object as a parameter
end
wait(5)
debounce = true
end
end)
now to the final part we go to the script we created before in ServerScriptService and we want to receive the character we passed as a parameter and reset its walkspeed after 5 seconds
so how do we do that?
simply with the .Event listener
your code should look like this:
local delayWalkspeed = game:GetService("ReplicatedStorage"):WaitForChild("DelayWalkspeed") -- get the bindable event
local delayTime = 5
delayWalkspeed.Event:Connect(function(character) -- get the character object that's been passed
delay(delayTime, function()
character.Humanoid.WalkSpeed = 16
end)
end)
i will leave you the project file in case you want to experiment with it more. ball.rbxl (30.1 KB)
have fun coding!