I'm trying to make a game where you must dodge blox being hurdled at you. One of The blox would have an ability where it slows you walking speed down for a short Amount of time. Can someone please help me!
How to make a brick that makes you slower when you touch it?
5 answers
@Above. He wants the walkspeed to go back to normal after a short amount of time..
script.Parent.Touched:connect(function(p)
local human=p.Parent:findFirstChild("Humanoid")
if human.className=="Humanoid" then
if human.WalkSpeed>10 then
human.WalkSpeed=10
wait(8)
pcall(function() --Dirty hax to prevent breaking if humanoid is nil.
human.WalkSpeed=16
end)
end
end
end)
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
hit.Parent.Humanoid.WalkSpeed = 10
end
end)
It's hot hard at all. You need to use the OnTouched function. Try this:
function onTouched(hit)
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed-5
end
script.Parent.Touched:connect(onTouched)
Note that you can change the 'hit.Parent.Humanoid-5' for a simple number, or replace the 5 by any other number. In the case you want the speed to come back to normal, add these two lines between hit.parent and end.
wait(5) --change time to whatever
hit.Parent.Humanoid.WalkSpeed = 16
Hope this helps.
Edit - Found a mistake in my script. Oops.
script.Parent.Touch:connect(function(c)
if c~=0 then
i=game:service("Players"):GetPlayerFromCharacter(c)
c.Character:FindFirstChild("Humanoid").WalkSpeed=c.Character:FindFirstChild("Humanoid").WalkSpeed-4
end end)
To do this the best way would be with the Touched event :
This code would be put in the brick that you want to slow down players
newspeed = 10 -- What the new walk speed will be
effecttime = 5 -- How long the slow down effect lasts
script.Parent.Touched:connect(function(hit) -- This function will fire when a part hits the brick
if hit == nil or hit.Parent == nil or hit.Parent:FindFirstChild("Humanoid") == nil then return end -- Checks to make sure that the part that hit it didn't get removed, has a parent and has a Humanoid in it
hum = script.Parent:FindFirstChild("Humanoid") -- Get the players humanoid
speed = hum.WalkSpeed -- Get the players WalkSpeed
for i = 0,1,0.05 do
hum.WalkSpeed = Vector3.new(hum.WalkSpeed,0,0):Lerp(Vector3.new(newspeed,0,0),i).x -- Fancy function to slowly apply the slowness effect
wait()
end
wait(effecttime)
for i = 0,1,0.05 do
hum.WalkSpeed = Vector3.new(newspeed,0,0):Lerp(Vector3.new(speed,0,0),i).x -- Fancy function to slowly remove the slowness effect
wait()
end
end)
I tried to explain as much of the code as I can but you can remove it
If you have any questions, concerns or just need some help with this PM me on ROBLOX!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
*i.Character:FindFirstChild("Humanoid").WalkSpeed=i.Character:FindFirstChild("Humanoid").WalkSpeed-4