Hey,
I’m making a round-based game, and right now, I have a system where item icons appear on a minimap at the top of the screen. The stage itself is loaded in at the beginning of the round, and unloaded at the end, and I’m using ChildAdded and ChildRemoved to make the item icons on the minimap appear as the real items do. Everything works perfectly fine in the first round, but the system breaks on the second; no icons appear at all, no matter how many items are added or removed.
Here’s the script that clones the icon:
local info = game.ReplicatedStorage:WaitForChild("Info")
local stage = workspace:WaitForChild("LucidLandscape")
info.Changed:Connect(function(NewValue)
if NewValue == "Starting round..." then
stage = workspace:WaitForChild("LucidLandscape")
end
end)
stage.ChildAdded:Connect(function(childrend)
if childrend.Name == "Bell" then --"Bell" is the name of the item I want to make an icon for
local clone1 = script.Parent.BellIcon:Clone()
clone1.Name = "ActiveBellIcon"
clone1.Position = UDim2.new((childrend.Position.X / 1050), 0, -0.38, 0) --Positions on the minimap accordingly
clone1.Parent = script.Parent.Parent
clone1.Visible = true
clone1.Object.Value = childrend --Sets its object value to the item just added
end
end)
…and here is the script INSIDE the clone:
local info = game.ReplicatedStorage:WaitForChild("Info")
local stage = workspace:WaitForChild("LucidLandscape")
stage.ChildRemoved:Connect(function(child)
if script.Parent.Object.Value == child then
script.Parent:Destroy()
end
end)
info.Changed:Connect(function(NewValue)
if NewValue == "Starting round..." then
stage = workspace:WaitForChild("LucidLandscape")
end
if NewValue == "Round over!" then
wait(1.1)
script.Parent:Destroy()
end
end)
I try and redefine what the “stage” variable is every time the round starts again. But it might not be working correctly; it might still be looking for changes in the OLD instance of the stage, which has since been destroyed since last round. Other than that, I’m not sure.
What might I be able to do?