Alright. I'm trying to make a block that slows you down while you're inside it, but gives you normal speed when you leave it. But for some reason, after making it so your walkspeed doesn't go infinitely high, it doesn't work at all. I added a print every other line starting in the functions, and it doesn't get past the line 5 print for some reason. I need this to work with custom speeds (which is why it uses division and multiplication) so don't suggest making the numbers fixed.
touched = false function touched(hit) if hit.Parent:FindFirstChild("Humanoid") and touched == false then print("line 5") touched = true print("line 7") hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed / 2 print("line 9") end end function touchended(hit) if hit.Parent:FindFirstChild("Humanoid") and touched == true then print("line15") hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed * 2 print("line17") touched = false print("line19") end end script.Parent.Touched:connect(touched) script.Parent.TouchEnded:connect(touchended)
I literally have no idea what's wrong with this and I am extremely confused and frustrated.
local touched = false function touched2(hit) if hit.Parent:FindFirstChild("Humanoid") and touched == false then print("line 5") touched = true print("line 7") hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed / 2 print("line 9") end end function touchended(hit) if hit.Parent:FindFirstChild("Humanoid") and touched == true then print("line15") hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed * 2 print("line17") touched = false print("line19") end end script.Parent.Touched:connect(touched2) script.Parent.TouchEnded:connect(touchended)
this worked for me. i changed the
function(touched) script.Parent.Touched:connect(touched)
to
function(touched2) script.Parent.Touched:connect(touched2)
it was connecting to the bool Value for some weird reason
Output:
line 5 line 7 line 9 line15 line17 line19 line 5 line 7 line 9 line15 line17 line19 line 5 line 7 line 9
it prints the touch ended prints on it while im walking on the brick in my testing server also, the WalkSpeed keeps changing from 8 to 16 while walking. it doesn't look like it speeds up though