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

Player can still stand/walk on platform after CanCollide is set to false. Is there a way to fix it?

Asked by 2 years ago
Edited 2 years ago

I am building an obby, and one of the stages is where there are multiple platforms, that when touched by the player, fade away and disappear (Transparency = 1 and canCollide = false). However, when the player touches the platform, after fading away, the player can still stand and walk on the platform for multiple seconds. Also, I am new to scripting, so I am sorry if this is a very obvious problem. Here is the code that I used:

local p = script.Parent

function onTouch(part)
    for i=1,100 do
        p.Transparency = p.Transparency + 0.01
        wait(0.01)
    end
    p.CanCollide = false
    wait(2.5)
    p.Transparency= 0
    p.CanCollide = true
end

p.Touched:connect(onTouch)

2 answers

Log in to vote
0
Answered by
epoke466 100
2 years ago

First, fyi, you don't need the argument "part" in line 3 --Or at least I don't think you don't...

Second, I am not sure how to fix your CanColide method (It is the first thing to try in my opinion though) But, when things don't work, I like to improvise! Try reparenting the part to server/replicated storage, changing the transparency, and then reparenting to workspace.

local p = script.Parent

function onTouch(part)
    for i=1,100 do
        p.Transparency = p.Transparency + 0.01
        wait(0.01)
    end
    p.parent = game.ReplicatedStorage
    wait(2.5)
    p.Transparency= 0
    p.parent = workspace
end

p.Touched:connect(onTouch)
0
After deleting the for loop and replacing it with the Tween Service, it worked. Thanks so much! stupefy100 7 — 2y
0
You are welcome epoke466 100 — 2y
0
I guess that works too. epoke466 100 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Rewrite the code a bit like this

local p = script.Parent
p.Transparency = p.Transparency + 0.01

function onTouch()

    p.Transparency= 0
    p.CanCollide = false
    wait(2.5)
    p.Transparency = p.Transparency + 0.01
    p.CanCollide = true

end

p.Touched:connect(onTouch)

Quick question. Why do you need this part?

for i=1,100 do
        p.Transparency = p.Transparency + 0.01
        wait(0.01)
end
0
Probably to make it transparent smoothly NotThatFamouss 605 — 2y
0
i see... you can use tween service if what @NotThatFamouss said is true AProgrammR 398 — 2y
0
Yeah, didn't know about the tween service, so I just improvised. stupefy100 7 — 2y

Answer this question