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

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

Asked by 4 years ago
Edited 4 years ago

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)  
> 
0
pls up my reputation i helped you iuclds 720 — 4y

2 answers

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

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 :)

0
mines better fighter iuclds 720 — 4y
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? Mast3rStRix 43 — 4y
Ad
Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
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

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. FighterOmaga 50 — 4y
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??? Mast3rStRix 43 — 4y

Answer this question