✓ Accepted answer
Let's take a step back and think here.
What could we do differently besides a loop, to make it more effective?
##First
We need to create a new script in Workspace that will set the owner's name to nothing in the event he leaves. This is simple, so I won't go into to much detail other than the comments I leave.
function FactoryFind(place, name)
for _,v in pairs(place:GetChildren()) do
if v.Name == "Factory" then
if v.Factory.OwnerName.Value == name then
v.Factory.OwnerName.Value = ""
end
else
FactoryFind(v)
end
end
end
game.Players.PlayerLeaving:connect(function (oldPlayer)
FactoryFind(Workspace, oldPlayer.Name)
end)
##Now,
All we need to do is edit your current script to used the changed event. Let's first create the event:
Note: We are going to keep your regen and variables for consistency.
model = script.Parent.Factory
backup = model:clone()
ownerName = script.Parent.Factory.OwnerName
function Regen()
model:remove()
wait(1)
model = backup:clone()
model.Parent = script.Parent
model:makeJoints()
end
ownerName.Changed:connect(function (onChange)
if ownerName.Value == "" then
Regen
end
end)
##Finally..
###In theory, the code I have supplied you, and with the ways mentioned, you can figure out how to consider other possible means yourself in the future. Just need to always keep thinking, and remember, try to solve the problem, not just cover it.
####Note: I have done absolutely no testing with this. I am simply assuming the code given will work, as I do not have studio right now to run any tests on.
6 comments
Is there anything in the output?
The code works, I've tested it in a server via studio, when I left, everything regened nicely, but while testing with more players, it bugged once.
How did it bug? Bricks tweaked?
It regenerated in loops, even when I became an owner of that House, it said previous owners name + mine at the same time, the whole "tycoon" blinked with bought, and not yet bought items.
I believe the bug came from the -loop-
Probably did, there is no other way of this looping, is there a way to fix this?