I made a regenerate map button that only works the first time it is pressed, how do I fix?
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 -
1 | local button = script.Parent |
3 | local function onButtonActivated() |
4 | game.ReplicatedStorage.MapRegen:FireServer() |
5 | print ( "Server notified" ) |
8 | button.Activated:Connect(onButtonActivated) |
And script in server script service -
01 | local oldmap = game.Workspace:WaitForChild( "GameModel" ) |
02 | local newmap = game.ServerStorage:WaitForChild( "GameModel" ):Clone() |
04 | game.ReplicatedStorage.MapRegen.OnServerEvent:Connect( function (player) |
05 | oldmap:ClearAllChildren() |
07 | print ( "map destroyed" ) |
09 | newmap.Parent = game.Workspace |
Help would be much appreciated!