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

Why would this trigger before I touch the brick?

Asked by 8 years ago

So, in my game, I have an invisible sphere at the top of a ramp. It is anchored. When a person touches a brick, it is supposed to appear and become unanchored, therefore rolling down the ramp. Then, when someone touches the sphere, they are supposed to take 25 damage, and the sphere should slowly fade away, turning off cancollide. Here is the trigger script...

function onTouched(part)
script.Parent.Parent.Ball.Transparency = 0
script.Parent.Parent.Ball.Anchored = false
end

script.Parent.Touched:connect(onTouched)

And this is the ball script...

function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")

            if h ~= nil then
                h.Health = h.Health - 25
                script.Disabled = true
                for i = 1, 10 do
                    script.Parent.Transparency = script.Parent.Transparency - 1
                    wait(.2)
                end
                script.Parent.CanCollide = false
            end
        end


script.Parent.Touched:connect(onTouched)

When I first enter the game (not touching my trigger AT ALL!) the ball appears and rolls down. Then, when touched, it takes away the damage, deactivates, but it doesn't disappear. Help?

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

Making The Brick Transparent

The only problem that I see is in your second script. Parts turn completely transparent (invisible) at a transparency of 1. This means, that they start at 0, and you need to build it up, not take it down, to make the part transparent. To do that we'll use this:

function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if h ~= nil then
        h.Health = h.Health - 25
        script.Disabled = true
        for i = 1, 10 do
            script.Parent.Transparency = script.Parent.Transparency + .1
            wait(.2)
        end
        script.Parent.CanCollide = false
    end
end

script.Parent.Touched:connect(onTouched)

Anyways, that should now be fixed. Now for the other script.


Making The Part Appear

I'm not exactly sure if this is the problem or not, but I believe the part may be making contact with another part which is making it go off at the wrong time.

To fix this, we'll just need to make sure that it's a player touching the part, and not another part. We'll use this script:

function onTouched(part)
    if part.Parent:FindFirstChild("Humanoid") then
        script.Parent.Parent.Ball.Transparency = 0
        script.Parent.Parent.Ball.Anchored = false
    end
end

script.Parent.Touched:connect(onTouched)

Anyways, I believe that those would be the only problems, and if I did everything correctly, they should be fixed now.


If you have any further problems/questions, please leave a comment below. Hope I helped :P

-Dyler3

Ad

Answer this question