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!
Figured it out. Put variables in script service in the function itself.