So this is my first time im trying to create any game and code it by myself. My regeneration script just break buttons everytime after first player and i dont know whats the reason and how it happens. Explain in idiot language, please. Thank you for help!
-- regeneration script local Original = script.Parent:FindFirstChild("Tycoon") function reset() if Original then local backup = Original:clone() Original:destroy() wait(1) backup.Parent = script.Parent end end local Players = game:GetService("Players") Players.PlayerRemoving:connect(reset) -- function for buttons, maybe this could give you a clue of whats wrong for i,v in pairs(Buttons:GetChildren()) do local Object = Items:FindFirstChild(v.Object.Value) if Object then local TestLOL = Object:Clone() Object:Destroy() if v:FindFirstChild("Dependency") then v.Button.CanTouch = false v.Button.Transparency = 1 v.Button.CanCollide = false v.Button.SurfaceGui.Enabled = false coroutine.wrap(function() if Items:WaitForChild(v.Dependency.Value) then v.Button.CanTouch = true v.Button.Transparency = 0 v.Button.CanCollide = true v.Button.SurfaceGui.Enabled = true end end)() end v.Button.Touched:Connect(debounce(function(touch) if Credits.Value >= v.Price.Value and CheckOwner(touch) then Credits.Value -= v.Price.Value TestLOL.Parent = Items v:Destroy() end end)) end end
it's because the button code has already run
try this
-- regeneration script local Original = script.Parent:FindFirstChild("Tycoon") function reset() if Original then local backup = Original:clone() Original:destroy() wait(1) backup.Parent = script.Parent for i, v in pairs(backup:FindFirstChild("Buttons"):GetChildren()) do -- adding this script to make it run again on the cloned version local Object = Items:FindFirstChild(v.Object.Value) if Object then local TestLOL = Object:Clone() Object:Destroy() if v:FindFirstChild("Dependency") then v.Button.CanTouch = false v.Button.Transparency = 1 v.Button.CanCollide = false v.Button.SurfaceGui.Enabled = false coroutine.wrap(function() if Items:WaitForChild(v.Dependency.Value) then v.Button.CanTouch = true v.Button.Transparency = 0 v.Button.CanCollide = true v.Button.SurfaceGui.Enabled = true end end)() end v.Button.Touched:Connect(debounce(function(touch) if Credits.Value >= v.Price.Value and CheckOwner(touch) then Credits.Value -= v.Price.Value TestLOL.Parent = Items v:Destroy() end end)) end end end end local Players = game:GetService("Players") Players.PlayerRemoving:connect(reset) -- This won't run in the cloned version because it has already run in the non cloned version for i,v in pairs(Buttons:GetChildren()) do local Object = Items:FindFirstChild(v.Object.Value) if Object then local TestLOL = Object:Clone() Object:Destroy() if v:FindFirstChild("Dependency") then v.Button.CanTouch = false v.Button.Transparency = 1 v.Button.CanCollide = false v.Button.SurfaceGui.Enabled = false coroutine.wrap(function() if Items:WaitForChild(v.Dependency.Value) then v.Button.CanTouch = true v.Button.Transparency = 0 v.Button.CanCollide = true v.Button.SurfaceGui.Enabled = true end end)() end v.Button.Touched:Connect(debounce(function(touch) if Credits.Value >= v.Price.Value and CheckOwner(touch) then Credits.Value -= v.Price.Value TestLOL.Parent = Items v:Destroy() end end)) end end
just comment if it's not working
Here's my regeneration script's final form (Almost.. Im too lazy and tired right now to add checking if its owner or not, so it triggers everytime someone leave)
local Original = game.ServerStorage.StoredTycoons.A1 -- link to the object you want to clone local Players = game:GetService("Players") local Owner = script.Parent.Tycoon.Values.OwnerVal -- value that stores owner's name Copy = Original:Clone() Players.PlayerRemoving:connect(function(Player) if Copy.Parent ~= workspace then Copy.Parent = workspace script.Parent:Destroy() end end)