Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part that gives u speed on touch?

Asked by 5 years ago

How to make a part when you touch it, you will get speed. Sorry for asking but I'm new to coding

2 answers

Log in to vote
0
Answered by 5 years ago

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
1
bad EXpodo1234ALT 18 — 5y
0
I agree, bad Spjureeedd 385 — 5y
Ad
Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago
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.

Answer this question