So I have this local script under startergui that is supposed to work like this: There are 7 cubes around the game that you need to click for an egg’s badgegiver to work, and there is a sign that has a counter GUI of how many cubes you got, so basically just to keep track.
Now the script works perfectly fine except for when the player resets and keeps hunting for the rest of the cubes, they stop working (they don’t change color, and nothing happens to the cubes) & it doesn’t give me anything in output. How do I fix it so that nothing resets and the script keeps working even if the player resets?
Current localscript inside startergui: (a bit messy sorry, but I like it this way so that I can understand it easier)
local Part1 = game:GetService('Workspace'):WaitForChild("Cube1")
local Part2 = game:GetService('Workspace'):WaitForChild("Cube2")
local Part3 = game:GetService('Workspace'):WaitForChild("Cube3")
local Part4 = game:GetService('Workspace'):WaitForChild("Cube4")
local Part5 = game:GetService('Workspace'):WaitForChild("Cube5")
local Part6 = game:GetService('Workspace'):WaitForChild("Cube6")
local Part7 = game:GetService('Workspace'):WaitForChild("Cube7") --== Change this to what you want, and to the parts name
--== Then add all the other parts
local counter = game.Workspace.Throne.Sign.Counter.SurfaceGui.TextLabel
local checks = 0 --== This will be counting how many have been pressed
local function checkCount() --== Function for checking the counts (this is optional, if you want something else let me know)
if checks == 7 then
game.Workspace.Throne["Sorcus Egg"].BadgeGiver.Enabled = true
end
end
Part1.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part1.ClickDetector:Destroy() --== So it can't be pressed again
Part1.Color = Color3.fromRGB(189, 0, 0)
Part1.Glow.Enabled = false
Part1.ParticleEmitter.Enabled = false
for _, child in Part1:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part2.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part2.ClickDetector:Destroy() --== So it can't be pressed again
Part2.Color = Color3.fromRGB(189, 0, 0)
Part2.Glow.Enabled = false
Part2.ParticleEmitter.Enabled = false
for _, child in Part2:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part3.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part3.ClickDetector:Destroy() --== So it can't be pressed again
Part3.Color = Color3.fromRGB(189, 0, 0)
Part3.Glow.Enabled = false
Part3.ParticleEmitter.Enabled = false
for _, child in Part3:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part4.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part4.ClickDetector:Destroy() --== So it can't be pressed again
Part4.Color = Color3.fromRGB(189, 0, 0)
Part4.Glow.Enabled = false
Part4.ParticleEmitter.Enabled = false
for _, child in Part4:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part5.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part5.ClickDetector:Destroy() --== So it can't be pressed again
Part5.Color = Color3.fromRGB(189, 0, 0)
Part5.Glow.Enabled = false
Part5.ParticleEmitter.Enabled = false
for _, child in Part5:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part6.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part6.ClickDetector:Destroy() --== So it can't be pressed again
Part6.Color = Color3.fromRGB(189, 0, 0)
Part6.Glow.Enabled = false
Part6.ParticleEmitter.Enabled = false
for _, child in Part6:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)
Part7.ClickDetector.MouseClick:Connect(function() --== Add this for each button
Part7.ClickDetector:Destroy() --== So it can't be pressed again
Part7.Color = Color3.fromRGB(189, 0, 0)
Part7.Glow.Enabled = false
Part7.ParticleEmitter.Enabled = false
for _, child in Part7:GetChildren() do
if child:IsA("Decal") then
child.Transparency = 1
end
end
checks += 1 --== Counts that the player pressed a button
checkCount() --== Run this after each button is pressed or run it in a loop
counter.Text = checks
end)