I'm trying to make a door that when clicked, makes whoever clicked it the owner of the door as long as nobody owns it. If someone does own it, you can't open it unless you own it. My main issue is the "clickey" function - it doesn't work, for some reason. It's connected to a ClickDetector. There are no errors, but the DoorOwner variable doesn't get set.
owner = script.Parent.Parent.DoorOwner function clickey(playerwhoclicked) if owner.Value == "nobody" then owner.Value = playerwhoclicked.Name script.Parent.Parent.Back.TextLabel.Text = "Owned by" .. playerwhoclicked.Name script.Parent.Parent.Front.TextLabel.Text = "Owned by" .. playerwhoclicked.Name elseif owner.Value == playerwhoclicked.Name then print("worky") end end --The loop below is perfectly fine. The function above is what I'm having trouble with. while true do wait(2) if owner.Value ~= "nobody" then player = game.Players:FindFirstChild(owner.Value, true) if player == nil then owner.Value = "nobody" end end end script.Parent.MouseClick:connect(clickey)
Your connection line is after a continual loop that does not stop. Therefore the event never gets established.
Use the PlayerRemoving event to detect if the player is leaving the server.
owner = script.Parent.Parent.DoorOwner function clickey(playerwhoclicked) if owner.Value == "nobody" then owner.Value = playerwhoclicked.Name script.Parent.Parent.Back.TextLabel.Text = "Owned by" .. playerwhoclicked.Name script.Parent.Parent.Front.TextLabel.Text = "Owned by" .. playerwhoclicked.Name elseif owner.Value == playerwhoclicked.Name then print("worky") end end --The loop below is perfectly fine. The function above is what I'm having trouble with. function PlayerRemoving(Player) --Define the new function. if owner.Value == Player.Name then --If the player that is leaving the game has the same name as the owner then do something. owner.Value = "nobody" --The script will now change the owner of the place to nobody. end end game.Players.PlayerRemoving:connect(PlayerRemoving) script.Parent.MouseClick:connect(clickey)