I’m trying to make a door that destroys itself locally for the person that has touched it. My current script is a local script in ReplicatedFirst
game.Workspace:WaitForChild("SpawnArea").SpawnDoor.Touched:Connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
game.Workspace.SpawnArea.SpawnDoor:Destroy()
end
end)
This current script destroys the door for everyone after one person has touched it, I want it to only destroy for the person that touched it
I have put the LocalScript in StarterCharacterScripts and StarterPlayerScripts and both have yielded the same result. i tested it in studio and in game with an alt account: when i touched (opened) the door with one account it opened on the other account’s screen as well
Try putting this script into StarterPlayerScripts:
local spawnDoor = game.Workspace:FindFirstChild("SpawnArea").SpawnDoor
spawnDoor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") then
spawnDoor:Destroy()
end
end)
Destroy() now supposedly replicates so I wouldn’t use it. What you can do is send an event when touched to the client to make the door invisible and non-collidable.
Is the door anchored? ‘Cause it may be a network ownership problem. If it’s not anchored, it’s very possible that the player that gets the closest to the door also gains ownership on said door, so when destroying it on the client they also destroy it on the server.
To do that, you need a Script, LocalScript and RemoteEvent
Add the script inside your door.
Add the Local Script inside of StarterGui
Add the RemoteEvent inside ReplicatedStorage
For the script, code this:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.RemoteEvent:FireClient(player)
end
end)
If your door is anchored, then ignore this comment. Otherwise, my best guess is that this is an issue of NetworkOwnership.
The nearest player to an unanchored object in your game always has some control over its position and movement properties by default. It’s annoying, but there’s IS a way to reverse that.
Try putting this in a serverscript (that means you should try it in a normal script, not a localscript):
local spawnDoor = workspace:WaitForChild("SpawnArea").SpawnDoor
spawnDoor:SetNetworkOwner(nil)
someone already said that, and based on the fact that it’s not marked as a solution, the poster is probably too lazy/incompetent to figure out how to use remote events.