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

How to remove model when player touches? I add a script in model but it doesnt work

Hello, I am having trouble removing models all together. It s supposed to remove the model everytime the player touches but it won't work How can I remove the model when the player touches it? The code I am using right now deletes only the part on which the script is while I want the whole thing Regards,

This is the code i ve been using:

> script.Parent.Touched:Connect(function(grow)
> 	function touch()
> 	script.Parent:remove()
> end 
> 
> script.Parent.Touched:connect(touch)
> end)	
> 

1 comment

0

pls up my reputation i helped you

2 answers

✓ Accepted answer

So if you want to remove a model if a player touches a part of the model this should work.

This script would go into the part you want to touch.

script.Parent.Touched:Connect(function(hit) --Detects if something touches the part.
	local model = script.Parent.Parent --Defines what the model is.

	if hit.Parent then --Checks if hit has a parent.
		if hit.Parent:FindFirstChild("Humanoid") then --Checks if it has a humanoid.
			model:Destroy() --If it does then destroy the model.
		end
	end
end)

This would destroy the model if a player touches it.

Upvote if this helps :)

2 comments

0

mines better fighter

0

Thank you so much! this works perfectly! and deletes the whole model Awesome! Is there a way to bring it back maybe after a timer ?or after the round ends?

script.Parent.Touched:Connect(function(hit) -- if it gets hit
game.Workspace.YOURMODELNAME:Remove() -- the  model gets removed
end) -- then it all ends

No need for all that extra

2 comments

0

This might not work well. Since the event fires when ANYTHING touches the part even being on the ground would cause the model to be destroyed.

0

Thanks a lot is there a way to bring it back later maybe after a timer or when the "game ends? and a new one begins???

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