This is a repost since the other thread died out quickly
So hey, I am trying to fix this regeneration script for this RC car demo. It duplicates the car by the amount of players for some reason. This is the result I do not want. Here is how it happens:
1 player: RC car regenerates like normal, expected result
2 players: RC car regenerates and adds another car; not expected result
3 players: RC car regenerates and adds 2 more cars; not expected result …and so on.
Here is the code, I based it off of an old regenerate script:
model = game.Workspace.Lowenherz -- Change "Compressor" to the name of your model.
new = model:clone()
enabled = true
game.ReplicatedStorage.LowenherzRemotes.RegenLowenherz.OnServerEvent:Connect(function()
if enabled then
model:Destroy()
script.Parent["Car Ignition Startup"]:Play()
enabled = false
wait(0.3) -- This is how long it will take to regen
model = new:clone()
model.Parent = game.Workspace
wait(5) -- This is how long it will take for the regen button to be enabled after being used
enabled = true
end
end)
Here is example if you want to know the structure: example.rbxl (71.2 KB)
I would recommend putting your code in a code block instead of quoting it. By the way, please format your code so it is readable to others trying to help you.
Well, you say if enabled is true to destroy the model, but it should be if enabled is false it destroys the model, since it is true when it is supposed to be spawnable. Maybe that will fix it?
model = game.Workspace.Lowenherz -- Change "Compressor" to the name of your model.
new = model:clone()
enabled = true
game.ReplicatedStorage.LowenherzRemotes.RegenLowenherz.OnServerEvent:Connect(function()
if enabled == false then -- the only line I changed - Ty_IsHomeSchooled
model:Destroy()
script.Parent["Car Ignition Startup"]:Play()
enabled = false
wait(0.3) -- This is how long it will take to regen
model = new:clone()
model.Parent = game.Workspace
wait(5) -- This is how long it will take for the regen button to be enabled after being used
enabled = true
end
end)
You’re cloning the clone of the model. try this. also you had nothing saying that if enabled was false to cut the script.
model = game.Workspace.Lowenherz -- Change "Compressor" to the name of your model.
enabled = true
game.ReplicatedStorage.LowenherzRemotes.RegenLowenherz.OnServerEvent:Connect(function()
if enabled then
script.Parent["Car Ignition Startup"]:Play()
model:Destroy()
enabled = false
wait(0.3) -- This is how long it will take to regen
new = model:clone()
new.Parent = game.Workspace
wait(5) -- This is how long it will take for the regen button to be enabled after being used
enabled = true
elseif enabled == false then
return
end
end)