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

How to make player walk slow when he is standing on a part?

Asked by
14dark14 167
4 years ago

If you go in the mud your character's walk speed will change to 10 and when you get out of the mud it will go back to 16. How do you check if the player has left the mud?

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        humanoid.WalkSpeed= 10
    end
end)
0
soul sand lol GAMER_64T 32 — 4y

4 answers

Log in to vote
1
Answered by 4 years ago

https://developer.roblox.com/en-us/api-reference/event/BasePart/TouchEnded

Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Try using the TouchEnded RBXScriptSignal connected to a function. It will fire whenever the touch has ended.

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if humanoid then
        humanoid.WalkSpeed = 10
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if humanoid then
        humanoid.WalkSpeed = 16
    end
end)
Log in to vote
1
Answered by 4 years ago

Use a touched ended event

script.Parent.Touched:Connect(function(hit)
                local Humanoid = hit.Parent:FindFirstChild("Humanoid")
                if (Humanoid ~= nil) then
                    Humanoid.WalkSpeed = 10

                    script.Parent.TouchedEnded:Connect(function(hit)
                     local Humanoid = hit.Parent:FindFirstChild("Humanoid")
                    if (Humanoid ~= nil) then
                    Humanoid.WalkSpeed = 16
                end
            end)

sorry for lack of elaboration

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

If you use touch ended, it might be funky and your speed may flicker (and the player could just jump). Another way to do this is to check if a player is inside of a certain area. I randomly found this guide about this on script helpers here. Personally I haven't read too much of it, but it might help.

Edit: for an unrotated part, it's easy to tell if a player is in it. Assume p1 and p2 are two oppisite corners of the affected area.

lp = Vector3.new(math.min(p1.x, p2.x), math.min(p1.y, p2.y), math.min(p1.z, p2.z))
up = Vector3.new(math.max(p1.x, p2.x), math.max(p1.y, p2.y), math.max(p1.z, p2.z))

local function checkifinarea(point)
    if (point.x>=lp.x and point.x<=mp.x) and (point.y>=lp.y and point.y<=mp.y) and (point.z>=lp.z and point.z<=mp.z) then
    return true
else
    return false
    end
end

Answer this question