How to locally delete a part?

I am trying to make a slenderman game and I want the page to delete once someone collects it for themself but for everyone else in the server it is still there. My script doesn’t work does anyone know how to do this?

script.Parent.ProximityPrompt.Triggered:Connect(function()
	print("triggered")
	script.Parent:Destroy()
end)

And I used a localscript for it and it doesn’t even print triggered in the output

You can do the code you put on a server script, and then fire a remote event to the client to locally delete it. Not sure if it’s the best way to go, but it works.

Local scripts don’t execute when placed inside the ‘Workspace’ container.

1 Like

doesn’t work when i do it nothing happens. did i do something wrong?

normal script

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	script.Parent.Collect:FireClient(player)
end)

local script

script.Parent.Collect.OnClientEvent:Connect(function(player)
	script.Parent:Destroy()
end)

yeah but i seen other games delete parts locally so im trying to figure out how to do this

As @Forummer said,

LocalScripts do not work inside of workspace. Try putting the script in ServerScriptService, defining the proximityprompt variable, and handling it from there.

Maybe also try putting the LocalScript in StarterPlayerScripts.

Put the script inside the ‘StarterPlayerScripts’ container and reference the prompt/part from there, i.e;

local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Part = Workspace:WaitForChild("Part")
local Prompt = Part:WaitForChild("ProximityPrompt")

local function OnTriggered(Player)
	if Player ~= LocalPlayer then return end
	Part:Destroy()
end

Prompt.Triggered:Connect(OnTriggered)
1 Like