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

I made a regenerate map button that only works the first time it is pressed, how do I fix?

Asked by 2 years ago

I've created a button that all players can use that regenerates the game map ("GameModel" in workspace). I can't figure out why it only works the first time it's pressed. I have a remote event named MapRegen in replicated storage. I also have a local script in the button -

local button = script.Parent

local function onButtonActivated()
    game.ReplicatedStorage.MapRegen:FireServer()
    print("Server notified")
end

button.Activated:Connect(onButtonActivated)

And script in server script service -

local oldmap = game.Workspace:WaitForChild("GameModel")
local newmap = game.ServerStorage:WaitForChild("GameModel"):Clone()

game.ReplicatedStorage.MapRegen.OnServerEvent:Connect(function(player)
    oldmap:ClearAllChildren()
    oldmap:Destroy()
    print("map destroyed")
    wait(.5)
    newmap.Parent = game.Workspace
    print("Map regen")
end)

Help would be much appreciated!

0
I believe you are deleting the original. then `newmap` has nothing to clone, try adding a unique name to the specific clone. Pixel448 0 — 2y
0
I could be wrong but it might be enough for you to spot something Pixel448 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Figured it out. Put variables in script service in the function itself.

Ad

Answer this question