I want to make it so when I press the button the map in workspace is destroyed and the map from lighting is cloned and put into the workspace.
The first time the function runs it works, however trying to do it a second time will not do anything. https://gyazo.com/c6213d709926392adbb98bd435599ea0
(Gif was cut to fit more into a short time frame)
I have tried changing the WaitForChild into FindFirstChild, same result.
local remote1 = game.ReplicatedStorage:WaitForChild("RemoteEvent2")
local newmap = game.Lighting:FindFirstChild("Map")
local map = workspace:FindFirstChild("Map")
local function onremote1()
newmap:Clone()
map:Remove()
wait(5)
newmap.Parent = workspace
end
remote1.OnServerEvent:Connect(onremote1)
Here is the local script it is fired from incase that has any correlation.
local remote1 = game.ReplicatedStorage:WaitForChild("RemoteEvent2")
function cast()
remote1:FireServer()
end
script.Parent.MouseButton1Click:Connect(cast)
If you have any idea what is going on and how I can fix it, please shoot me a reply! Thanks!
-shkip_not
(This was fixed, keep in mind that PAGOTATZIS2’s post also helped with it!)
map:Remove() removes the map you defined in the variable once instead try replacing it with workspace.Map:Destroy() so it gets updated every time you run it!
local remote1 = game.ReplicatedStorage:WaitForChild("RemoteEvent2")
local function onremote1()
local newmap = game.Lighting:FindFirstChild("Map"):Clone()
local map = workspace:FindFirstChild("Map")
map:Destroy()
wait(5)
newmap.Parent = workspace
end
remote1.OnServerEvent:Connect(onremote1)
you should make a new variable when cloning map inside lighting because you’re just replacing map inside Lighting to Workspace so next time you click to button there’s no map inside Lighting to clone
you can try this updated code:
local remote1 = game.ReplicatedStorage:WaitForChild("RemoteEvent2")
local function onremote1()
local newmap = game.Lighting:FindFirstChild("Map")
local map = workspace:FindFirstChild("Map")
local newestmap = newmap:Clone()
map:Remove()
wait(5)
newestmap.Parent = workspace
end
remote1.OnServerEvent:Connect(onremote1)