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

My brick wont Destroy when touched?

Asked by 5 years ago
Edited 5 years ago

the = sign is underlined red but I dont know how I could fix the problem.

01local ShyWhenTouched = script.Parent
02 
03 
04 
05if ShyWhenTouched.Touched = true then
06 
07    ShyWhenTouched:Destroy()
08 
09 
10 
11end

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The reason your script does not work is because in line 5, an event (like your touched event) can only do 2 things: connect a function

1local part= script.Parent
2 
3part.Touched:Connect(function(hit)
4if hit.Parent:FindFirstChild("Humanoid") then
5hit.Parent.Humanoid:TakeDamage(100)
6end

or wait to do code below it.

1local part= script.Parent
2 
3part.Touched:Wait()
4print("part has been touched")

So you would do the following instead, where you connect a function that destroys the part when it's touched:

1local ShyWhenTouched = script.Parent
2 
3ShyWhenTouched.Touched:Connect(function()
4ShyWhenTouched:Destroy()
5end

In conclusion, there is no "bool" to a touched event; it can only connect a function or wait to do code below the line. Hope that works for you, and that you have learned something new :)

Ad
Log in to vote
0
Answered by 5 years ago

part.Touched is an event, therefore, your script should look like this:

01local ShyWhenTouched = script.Parent
02 
03 
04 
05ShyWhenTouched.Touched:Connect(function()
06 
07    ShyWhenTouched:Destroy()
08 
09 
10 
11end)

Answer this question