I’m trying to make a part that disappears when a player touches it for example, Player 1 touches a part and player 1 no longer can see the part, but player 2 who did not touch the part yet still sees the part.
This code is local script located in starter player scripts
local part = game.Workspace.SunFragment1.sunfragment – a part
part.Touched:Connect(function(PartTouched)
if PartTouched.Parent:FindFirstChild("Humanoid")then
part:Destroy()
end
end)
I haven’t found any solutions yet to this problem.
Make sure your script is where a local script can run (not workspace , serverstorage or serverscriptservice)
local part = game.Workspace.SunFragment1.sunfragment
local Player = game.Players.LocalPlayer
part.Touched:Connect(function(PartTouched)
if PartTouched.Parent.Name == Player.Name then -- If the players name = the player then it destorys the part on his client and not others
part:Destroy()
end
end)
You’re likely facing this issue because the .Touched event on each client will detect that the part was touched and destroy it when it’s touched, no matter which client touched it. Just check if the name matches the client’s name after it’s touched and before it’s destroyed.
if PartTouched.Parent.Name == game.Players.LocalPlayer.Name then
part:Destroy()
end