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

How to destroy object locally?

I’m sorry if my question is worded wrong, I think locally is the right term to use. How would you go about destroying an object when it is touched, but only for the player that touches it? It will still be there for other players until they touch it.

Thanks in advance so much

1 comment

0

Destroy the part from a local script

1 answer

I created this LocalScript

local part = game:GetService("Workspace"):WaitForChild("Part") -- change "Part" to the part name

part.Touched:Connect(function(touch)
	local player = game:GetService("Players"):GetPlayerFromCharacter(touch.Parent)
	if player ~= nil then
		if player == game:GetService("Players").LocalPlayer then
			part:Destroy()
		end
	end
end)

Also, place this localscript in StarterPack

Just Change the Part in the local part to your parts name and you should be fine.

4 comments

0

Thanks a lot! Worked perfectly.

0

Well actually, I tested it online and it doesn't work. In the studio it worked though. Online my character just climbs on top of the object, it don't get destroyed or anything.

0

Cancel that. Got it working. My mistake, your code was perfect. Thanks again

0

No problem. If you could please just accept that answer it would be great! it gives us both REP points!

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