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 9 years ago
1script.Parent.Touched:connect(function()
2    script.Parent:FindFirstChild("Humanoid")
3    script.Parent.CanCollide = false
4    if
5        script.Parent:FindFirstChild("Humanoid") == false then
6        script.Parent.CanCollide = true
7    end
8end)

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 9 years ago

You HAVE to check for the humanoid BEFORE ANYTHING ELSE.

1script.Parent.Touched:connect(function()
2    if script.Parent:FindFirstChild("Humanoid") then
3        script.Parent.CanCollide = false
4    elseif not script.Parent:FindFirstChild("Humanoid") then
5        script.Parent.CanCollide = true
6    end
7end)

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:

01script.Parent.CanCollide = true
02 
03script.Parent.Touched:connect(function(hit) -- oops forgot this important part
04    if hit.Parent:FindFirstChild("Humanoid") then
05        script.Parent.CanCollide = false
06    end
07end)
08 
09script.Parent.TouchEnded:connect(function(hit)
10    if hit.Parent:FindFirstChild("Humanoid") then
11        script.Parent.CanCollide = true
12    end
13end)
0
Pretty sure you don't need not after elseif Alpha_Toon 57 — 9y
0
Thanks! james24dj 90 — 9y
0
it just makes more sense to me, you can use if thing == false but i like if not bubbaman73 143 — 9y
0
Nvm, this doesn't work. It stays cancollided. It doesn't go to false, it stays true. james24dj 90 — 9y
View all comments (2 more)
0
oooh, hold on bubbaman73 143 — 9y
0
fixed i think bubbaman73 143 — 9y
Ad

Answer this question