Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use the FindFirstChild to run functions?

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?

2 comments

0

How do insert my code properly? I couldn't find anything telling me how.

0

Just click the "Code Block" button when posting. And put your code(s) between the ~~~~~~~~~~~~~~~~~'s

2 answers

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.

1 comment

0

My main problem is that when the FindFirstChild function returns a nil value, it should delete the model, but it doesn't

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

Change line 7 to this:

script.Parent:Destroy()

This discussion is preserved as it was. New answers, comments, and votes are closed.