Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Regeneration script causing massive duplication?

Asked by 4 years ago

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)
0
Where is the Serverscript Located at? ShaShxa 105 — 4y
0
Inside the GUIButton. Along with the LocalScript. squidiskool 208 — 4y

1 answer

Log in to vote
1
Answered by
ShaShxa 105
4 years ago
Edited 4 years ago

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.

Ad

Answer this question