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

Why is this PARTIALLY doing my script?

Asked by 8 years ago
script.Parent.Touched:connect(function()
    script.Parent:FindFirstChild("Humanoid")
    script.Parent.CanCollide = false
    if
        script.Parent:FindFirstChild("Humanoid") == false then
        script.Parent.CanCollide = true
    end
end)

Supposed to turn the brick's CanCollide to false if a Humanoid is touching it, and when the player is not on/in the brick, cancollide goes back to true.

All this script does is turn the canCollide to false and it stops there.

1 answer

Log in to vote
3
Answered by 8 years ago

You HAVE to check for the humanoid BEFORE ANYTHING ELSE.

script.Parent.Touched:connect(function()
    if script.Parent:FindFirstChild("Humanoid") then
        script.Parent.CanCollide = false
    elseif not script.Parent:FindFirstChild("Humanoid") then
        script.Parent.CanCollide = true
    end
end)

you didnt check for it. you just sent an empty request. it finds it but doesnt know what to do with that info

EDIT: So it sent the empty request and moved on to setting it to false, then checking for the other condition. (Note: elseif is better practice)

REEDIT:

script.Parent.CanCollide = true

script.Parent.Touched:connect(function(hit) -- oops forgot this important part
    if hit.Parent:FindFirstChild("Humanoid") then
        script.Parent.CanCollide = false
    end
end)

script.Parent.TouchEnded:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        script.Parent.CanCollide = true
    end
end)
0
Pretty sure you don't need not after elseif Alpha_Toon 57 — 8y
0
Thanks! james24dj 90 — 8y
0
it just makes more sense to me, you can use if thing == false but i like if not bubbaman73 143 — 8y
0
Nvm, this doesn't work. It stays cancollided. It doesn't go to false, it stays true. james24dj 90 — 8y
View all comments (2 more)
0
oooh, hold on bubbaman73 143 — 8y
0
fixed i think bubbaman73 143 — 8y
Ad

Answer this question