Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Regeneration script causing massive duplication?

Doing this again since the last answer failed. So I'm making this RC car system, controlled by a tool. When the player clicks the button in the GUI, it fires a RemoteEvent from a local script. In a server script, it responds to that RemoteEvent and regenerates it. But the problem is that when there's more than 1 player, the script causes massive duplication. I still have no idea why this is happening, or what is causing it.

SERVER:

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)

LOCAL:

script.Parent.MouseButton1Click:connect(function()
    game.ReplicatedStorage.LowenherzRemotes.RegenLowenherz:FireServer()
end)

2 comments

0

Where is the Serverscript Located at?

0

Inside the GUIButton. Along with the LocalScript.

1 answer

✓ Accepted answer

Hello!

Since the ServerScript is inside the GUIButton, It will create one Server script for each PlayerGui. Means for example: If 5 Players are inside the Game, It will be run 5 times (The OnServerEvent gets connected 5 Times), Which causes Massive duplication. (Because the Serverscript got duplicated multiple times).

Try putting the Serverscript inside Serverscriptservice and see if that helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.