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

idk why this script wont work its not disabled, trying to make some thing diaper how do i fix?

Asked by 6 years ago

the script is not disabled

01local tri = "asd"
02function onTouch(part)
03    local humanoid = part.Parent:FindFirstChild("Humanoid")
04    if (humanoid ~= nil) then   -- if a humanoid exists, then
05        --humanoid.Health = 0   -- damage the humanoid
06    end
07    if humanoid then
08        tri = false
09    else
10        tri = true
11    end
12 
13    if tri == true then
14    part.Transparency = 1
15        part.CanCollide = false
View all 28 lines...
0
the humanoid health = 0 part is also a comment. (in line 05) TheluaBanana 946 — 6y
0
what r u trying to do exactly? TheluaBanana 946 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Im not 100% sure what your wanting but this is what I pieced together. (assuming you are wanting this script to affect a player when they touch the part)

01local tri = nil
02function onTouch(part)
03    local humanoid = part.Parent:FindFirstChild("Humanoid")
04    if (humanoid ~= nil) then   -- if a humanoid exists, then
05        --humanoid.Health = 0   -- damage the humanoid
06    end
07    if humanoid then
08        tri = true --switched to true
09    else
10        tri = false --switched to false
11    end
12 
13    if tri == true then
14    part.Transparency = 1
15        part.CanCollide = false
View all 24 lines...

Your problem was where you set tri equal to true or false, based on what I think your wanting, you mixed the two up. As shown above I flipped the true and false and it worked(shown with comments.) The way you had it set was, if the part was NOT a player then set the transparency = 1.

Personally I would do it this way. Instead of setting a variable equal to true or false based on whether or not the part is a player and then checking that variable to detect if the part indeed was a player, you can skip setting a variable and just run the code if it detects a humanoid. The end goal is the same the code is just shorter.

01local tri = nil
02function onTouch(part)
03    local humanoid = part.Parent:FindFirstChild("Humanoid"
04    if humanoid then --checks if part is a player, if not do nothing
05        part.Transparency = 1
06        part.CanCollide = false
07        wait(3)
08        part.Transparency = 0
09        part.CanCollide = true
10    end
11end
12script.Parent.Touched:connect(onTouch)
0
ikr TheluaBanana 946 — 6y
Ad

Answer this question