How Would I Destroy Local Parts?

I am trying to figure out how I would make a local part for every player, and then if someone were to touch it, it would only destroy that person’s local part. It is kind of like Royal High’s candy hunt for Halloween. How would I do this? (I am not that experienced with local parts). Thanks to any help I can get.:grin:

5 Likes

You can detect on the server if a player touches the part and then fire a remote event on the client that is handled in a local script and this local script destroys the part locally.

where would I put the part though I am confused on that because when I have it in workspace it destroys it for every player

1 Like

You’d do it exactly how you would on the server, but on the client.

In a LocalScript, you could do something like

local part = Instance.new("Part")
part.Position = Vector3.new(0,50,0)
part.Size = Vector3.new(5,5,5) -- Creates part and sets properties
part.Parent = game.Workspace

part.Touched:connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name] == game.Players.LocalPlayer then -- Checks if there's a player that touched it and if that player is the LocalPlayer
        part:Destroy()
    end
end)
10 Likes

You have to destroy it from a local script that handles the remote event I mentioned.

Or you can do like @Xiousa said but this doesn’t allow you directly to store any information on the server whether the player has touched the part or not.

can you do it with out manually creating the parts?

yes I know I am using the client

What do you mean by that? To make a local part, you’d need to make the part on the Client from a LocalScript.

ok I thought there was another way to do that, like make the model without a script

(oh well I guess I will make it manually then.:expressionless:)

If you want to make it only visible for localplayer make sure to change Parent or Part to LocalPlayer’s PlayerGui. I hope this helps. :herb:

That’s not how you make a Local Part. A part will not be displayed if it’s in PlayerGui; it would need to either be in CurrentCamera or Workspace.

I mean he can spawn a Part on a local script and it’s going to work. I have my VIP work like that if localscript finds out that player has VIP purchased it deletes vip door else not and works. :herb:

Edit: I just found out your script written above and yes that’s how it should be to work.

could you also make it where if you touched the part, it will not come back again?

1 Like

Here you go, add a normal script in a part:

script.Parent.Touched:Connect(function(hit)
  if game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name] == game.Players.LocalPlayer then 
  script.Parent:Destroy()
end

end)

I hope this helps. :herb:

so this works for it permanently not coming back at all? I am adding other local parts in this one script and I want the same part to disappear forever, if not I guess I can make 10 local scripts, but that is very messy.

Yes the script should be parent of a part. And yes this destroys every value out of workspace once player touches it and it should never show again. Make sure to use updated script thought. :herb:

yep I am, thanks for that.:grin:

wait how would I do this if they leave the game

You mean like to destroy all parts that were made by server and once player leaves it destroys them all?
I would simply use a PlayerRemoving and add function to it to destroy the part, simple as that. :herb: