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 4 years ago
Edited 4 years ago

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

local ShyWhenTouched = script.Parent



if ShyWhenTouched.Touched = true then

    ShyWhenTouched:Destroy()



end



2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 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

local part= script.Parent

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(100)
end

or wait to do code below it.

local part= script.Parent

part.Touched:Wait()
print("part has been touched")

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

local ShyWhenTouched = script.Parent

ShyWhenTouched.Touched:Connect(function()
ShyWhenTouched:Destroy()
end

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

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

local ShyWhenTouched = script.Parent



ShyWhenTouched.Touched:Connect(function()

    ShyWhenTouched:Destroy()



end)

Answer this question