How to make a part when you touch it, you will get speed. Sorry for asking but I'm new to coding
COMMUNITY QUESTION
Part that gives u speed on touch?
2 answers
Here we go:
local cooldown = false
function onTouch(part) --the brick that u get speed
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and cooldown == false then -- checks for player value
cooldown = true
human.WalkSpeed = 50 -- or whatever number (default is 16)
wait(3) -- cooldown
cooldown = false
end
end
script.Parent.Touched:connect(onTouch) -- the final part to give the player speed on touch
local Part = script.Parent
function onTouched(touchedPart)
local Character = touchedPart:FindFirstAncestorWhichIsA("Model")
if Character then
local Humanoid = Character.Humanoid
Humanoid.WalkSpeed = 100
end
end
Part.Touched:Connect(onTouched)
The code is fairly simple.
The code is basically a Server-Side script located inside of a part. We have a function which is connected to an event of when the part is touched. Inside the event, inside the parameters we have "touchedPart". We use touchedPart as a way to find the part that touched the speed giver for reference. We find the character by finding an ancestor who's object class is a model. We use a conditional statement to check if the Character exists, and if that's that case we'll get the Humanoid and set it's WalkSpeed to 100.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
bad
I agree, bad