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)

3 comments
Is the Parent on line 25 a ClickDetector? If not, then that may be your problem, as you can only use the event 'MouseClick' on a ClickDetector asset. :)
It's because you have a while loops which continually runs before reaching the MouseClick event connection line. What you could do is use the PlayerRemoving event and find if the owner (I am assuming you're making a tycoon) has left the server.
^