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

How to make friction change each time something is touched?

Asked by 6 years ago

I'm wondering if there's any way to make the friction of a brick change by a certain amount each time it is touched. Any help would be appreciated. Thanks!

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The code is quite simple. Put it inside of the part you desire.

--Reset friction after a set amount of time (debounced)
debounce = false

script.Parent.Touched:connect(function()
    if debounce == true then return end
    debounce = true
    local formerfriction = script.Parent.CustomPhysicalProperties.Friction
    script.Parent.CustomPhysicalProperties.Friction = 1 --Change to what you desire
    --Remove this part below if you don't want it to reset, but don't remove the end)
    wait(5) --Change to what you desire
    script.Parent.CustomPhysicalProperties.Friction = formerfriction
    debounce = false
end)

--Set friction as long as the part is being stepped on/touched
local OffFriction = 0.3
local OnFriction = 1

script.Parent.Touched:connect(function()
    script.Parent.CustomPhysicalProperties.Friction = OnFriction
end)

script.Parent.TouchEnded:connect(function()
    script.Parent.CustomPhysicalProperties.Friction = OffFriction
end)
0
Sorry for being so late, but thank you so much! Have a great day! ROCKANDROLL572 12 — 6y
Ad

Answer this question