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

How can I make onTouched() event work when jumping on a part?

Asked by 3 years ago
Edited 3 years ago

I am making a game with disappearing platforms, that fade to transparent and then turn canCollide off (after a second's delay), when a player touches them. The problem is, the onTouched() event does not seem to work when jumping, or if a player falls from above onto the intersection between 2 or more parts.

Because these are platforms that a player stands on, I cannot use the normal advice I find for kill boxes with the same problem, which is to turn canCollide off. I also tried some other advice I found, which is to make a transparent and untouchable part that has the functionality of the part you wanted, and then use the original part as just for the look you wanted. You were supposed to place the transparent "functional" part slightly above the original part. Then I realized that when I was all finished, it turned out that i had some transparent parts turning transparent and then dissappearing, and my original parts were still there. Again, it was advice made for kill boxes where OnTouched wasn't working, not something you need to stand on.

I am willing to show code snippets if it makes any difference.

1 answer

Log in to vote
0
Answered by 3 years ago

Hello!

I think you're trying to make a part disappear (well with transparency and cancollide) when a player goes on it. If I'm wrong, tell me.

So this is the code you would use

(you would put this script in the part you're using)

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local function FadeAway()
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.05)
        end
        FadeAway()
        script.Parent.CanCollide = false
    end
end)
Or, another thing that I think that you're trying to do is where it doesn't run when you touch the part. I know what you're talking about, where players can just hold the spacebar and evade the script from running. I get it, it's pretty annoying. Fortunately, this is a simple fix. Instead of using script.Parent, you're gonna reference the part the boring through game.Workspace.

To start off, make a copy of the part and set the transparency to 1, and cancollide to true and put it 1 stud above the part you're trying to make fade away. Then in that script, you're going to insert this script
local Part = game.Workspace.YourPartName

Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.Transparency = Part.Transparency + 0.1
        wait(0.05)
        Part.CanCollide = false
    end
end)
Put the name of the part you're trying to make disappear in "YourPartName"

Hopefully this works!
0
bro idk why the the normal text is in lua code please forgive me i have no idea what went wrong likejagar 17 — 3y
0
thank you for your answer, i thought about doing it this way, but the problem is that I have about 400 of these platforms, so I cant reference them, even if i named them like 'platform 1' 'platform 2' etc, I would have to change the code for all 400 of the invisible pieces so that each one corresponds to a part that you can see. Also it would be smart to put the transparency in a loop :) FinnBotF11 15 — 3y
Ad

Answer this question