local function newstage1()
local RGM = game.ServerStorage.Stages.s1st
local randomMap = RGM:GetChildren()[math.random(1,#RGM:GetChildren())]
randomMap:Clone().Parent = workspace.CurrentStages.c1st
end
newstage1() --- it works here
local timeRemaining = game.ReplicatedStorage.Value
timeRemaining.Changed:Connect(function()
if timeRemaining.Value == 0 then
local stage1model = game.Workspace.CurrentStages.c1st
stage1model:Destroy()
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
timeRemaining.Value = 10
wait(0.5)
newstage1() --it doesn't work here
end
end)
Try changing the local function
to a regular function, and set the newstage1()
after the Changed
Event?
1 Like
It doesn’t work because you destroyed the object it’s supposed to get parented to, in these 2 lines:
local stage1model = game.Workspace.CurrentStages.c1st
stage1model:Destroy()
So technically it gets cloned but doesn’t get parented to anything in the workspace.
2 Likes
1 Like