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 -

1local button = script.Parent
2 
3local function onButtonActivated()
4    game.ReplicatedStorage.MapRegen:FireServer()
5    print("Server notified")
6end
7 
8button.Activated:Connect(onButtonActivated)

And script in server script service -

01local oldmap = game.Workspace:WaitForChild("GameModel")
02local newmap = game.ServerStorage:WaitForChild("GameModel"):Clone()
03 
04game.ReplicatedStorage.MapRegen.OnServerEvent:Connect(function(player)
05    oldmap:ClearAllChildren()
06    oldmap:Destroy()
07    print("map destroyed")
08    wait(.5)
09    newmap.Parent = game.Workspace
10    print("Map regen")
11end)

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