Needing the script to * and / instead of instantly change

i have this script which is a basic speedboost for a character, only i dont want it to make the speed 50 but i want it to do the current speed of the character *5 and then wait 3 sec and then /5 so it goes back to the original speed since there are different speeds in the game itself.

local speedBoost = script.Parent

local function steppedOn(part)
	local parent = part.parent
	if game.Players:GetPlayerFromCharacter(parent)then
		parent.Humanoid.WalkSpeed = 50
		wait(3)
		parent.Humanoid.WalkSpeed = 16
	end
end

speedBoost.Touched:connect(steppedOn)

Hi, juste use a local Variable

local speedBoost = script.Parent

local function steppedOn(part)
	local parent = part.parent
	if game.Players:GetPlayerFromCharacter(parent)then
		local startSpeed=parent.Humanoid.WalkSpeed
		parent.Humanoid.WalkSpeed = startSpeed*5
		wait(3)
		parent.Humanoid.WalkSpeed = startSpeed
	end
end

speedBoost.Touched:connect(steppedOn)
1 Like

this doesnt quite work and i dont know why, when the speed in game is slow and i step on it i become ultra fast and then i become faster than the speed i was before i stepped on it

Add a cooldown

local speedBoost = script.Parent
local charCoolDown = {} --Create a dictonary
local coolDownDuration=5 -- cool down duration (second)

local function steppedOn(part)
	local parent = part.parent
	if not charCoolDown[parent] then
		if game.Players:GetPlayerFromCharacter(parent)then
			charCoolDown[parent]=true
			local startSpeed=parent.Humanoid.WalkSpeed
			parent.Humanoid.WalkSpeed = startSpeed*5
			wait(3)
			parent.Humanoid.WalkSpeed = startSpeed
			wait(coolDownDuration)
			charCoolDown[parent]=false
		end
	end
end

speedBoost.Touched:connect(steppedOn)
1 Like

well no i meant, basically, i start with speed 10 and stand on it. i become faster and thats okay, then when i become slower again i should become speed 10 again but actually i become faster than speed 10 even after the speed is over. i didnt step on it again.

You set walking speed to 10 in client side or server side?

1 Like

in the play button in studio? there are scripts that involve changing the walkspeed of the character in the game in general, thats why i need to fix it

can someone help? i need this done quik and i havent been able to find a solution
EDIT: nvm there was a problem with my part! thanks!

1 Like