Need help with walkspeed changer

Hello, I am making a walkspeed changer that changes the character’s speed inside the part. (In this case water.) The problem is when I change the walkspeed I want its speed to go back to normal when it comes out of the part. How can I do this?

This is the code I have right now.

local part = game.Workspace.water  
	
part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Walkspeed = 7
	end	
end)
3 Likes

Use TouchEnded.

Edit: Basically you copy the Touched again but this time change Touched to TouchEnded. At the modifying walkspeed, change it to 16, since you want to make the player walk normally.

--touched event here
part.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Walkspeed = 16
	end	
end)
2 Likes

Thanks for the help here’s the script if anyone comes by this post.

local part = game.Workspace.water -- Where your part is

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.WalkSpeed = 5 -- Speed
	
	end	
end)

part.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.WalkSpeed = 16 -- Speed
	end	
end)
1 Like