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

How to use the FindFirstChild to run functions?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I have been trying to make a script that destroys the model it is in when a certain block is destroyed. When I destroy the block, it explodes like it is meant to, but the model isn't removed. So far I have got:

 blueteamlive = script.Parent:FindFirstChild("Team Block")

while true do
    if blueteamlive ~= nil then
        game.Workspace.Spawns.Red = BrickColor.new(1001)
    else 
        script.Parent:remove()
    end

end

I have no idea if the script would work if nothing was inserted where I have put the Spawn brick color changer. I know something is wrong, but I don't know what. Can someone please help?

0
How do insert my code properly? I couldn't find anything telling me how. 1jumpingjack 0 — 10y
0
Just click the "Code Block" button when posting. And put your code(s) between the ~~~~~~~~~~~~~~~~~'s Tkdriverx 514 — 10y

2 answers

Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

Change this line:

game.Workspace.Spawns.Red = BrickColor.new(1001)

to this:

game.Workspace.Spawns.BrickColor = BrickColor.new(1001)

Assuming Spawns is a SpawnLocation, it has a "BrickColor" property that you can set. However, it doesn't have a property named Red.

0
My main problem is that when the FindFirstChild function returns a nil value, it should delete the model, but it doesn't 1jumpingjack 0 — 10y
Ad
Log in to vote
0
Answered by
Discern 1007 Moderation Voter
10 years ago

:remove() is deprecated. Use the Destroy method.

Change line 7 to this:

script.Parent:Destroy()

Answer this question