Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

After deleting the for loop and replacing it with the Tween Service, it worked. Thanks so much!

0

You are welcome

0

I guess that works too.

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

3 comments

0

Probably to make it transparent smoothly

0

i see... you can use tween service if what @NotThatFamouss said is true

0

Yeah, didn't know about the tween service, so I just improvised.

This discussion is preserved as it was. New answers, comments, and votes are closed.