Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I remove ownership of property when a local player exits/quits the game?

Asked by 5 years ago
Edited 5 years ago

Hello!

I am trying to incorporate a line into my script that would remove ownership from the property upon player exit and revert back to "No Owner" So a new player can take over:

--//Variables
local owner = script.Parent.OwnerName
local isOpen = false
local waitTime = 2
local door = script.Parent

--//Ensures that the door is closed
door.CanCollide = true
door.Transparency = 0
door.Anchored = true

script.Parent.Touched:connect(function(hit)
 local humanoid = hit.Parent:FindFirstChild("Humanoid")
 if humanoid then
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  if plr then
   --//A player
   if owner.Value == "" then
    --//No Current Owner, set player as new owner
    owner.Value = plr.Name
   elseif plr.Name == owner.Value then
    --//The owner
    if isOpen == false then
     isOpen = true
     door.CanCollide = false
     door.Transparency = 0.8
     wait(waitTime)
     door.CanCollide = true
     door.Transparency = 0
     isOpen = false
    end
    end
  end
 end
end)

and my parent script:

--//Variables
local model = script.Parent
local owner = script.Parent.Head.OwnerName

--//Initializes Name
function check()
 if owner.Value == "" then
  model.Name = "No current owner"
 else
  model.Name = owner.Value .. "'s Dorm Room"
 end
end

owner.Changed:connect(function()
 check()
end)
check()

Any help would be appreciated!

Thanks

0
game.Players.PlayerRemoved will help you Axdrei 107 — 5y
0
I might be wrong but when a player leaves the network owner of the instance is set to `nil` which means the server controls it. EpicMetatableMoment 1444 — 5y
0
:connect is deprecated use :Connect User#23989 0 — 5y
0
Can someone please explain where I would input game.Players.PlayerRemoved for this to work? bella_boopy 13 — 5y

Answer this question