Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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 -

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!

2 comments

0

I believe you are deleting the original. then newmap has nothing to clone, try adding a unique name to the specific clone.

0

I could be wrong but it might be enough for you to spot something

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.