DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:00pm
#1
Hello everyone, I made a collector, and when a player finished to collect all the parts I want the player to restart the collector system again.
Here is the script:
local Players = game.Players.LocalPlayer
wait(1)
container.Parent = game.Workspace
local collected = 0
for i, v in pairs(container:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function(player)
collected = collected + 1
game.Workspace.Sounds.Grabbed.Playing = true
v:Destroy()
local CollectedText = script.Parent
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Containers"
elseif collected == 4 then
CollectedText.Text = "4/15 Containers"
elseif collected == 5 then
CollectedText.Text = "5/15 Containers"
elseif collected == 6 then
CollectedText.Text = "6/15 Containers"
elseif collected == 7 then
CollectedText.Text = "7/15 Containers"
elseif collected == 8 then
CollectedText.Text = "8/15 Containers"
elseif collected == 9 then
CollectedText.Text = "9/15 Containers"
elseif collected == 10 then
CollectedText.Text = "10/15 Containers"
elseif collected == 11 then
CollectedText.Text = "11/15 Containers"
elseif collected == 12 then
CollectedText.Text = "12/15 Containers"
elseif collected == 13 then
CollectedText.Text = "13/15 Containers"
elseif collected == 14 then
CollectedText.Text = "14/15 Containers"
elseif collected == 15 then
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
print("Got it!")
end)
end
repeat wait() until collected == 15
print("Containers were found")
I hope you can help me, thank your for your time
Daronion
(Daronion)
November 10, 2022, 10:04pm
#2
I believe you could give this a try:
local Players = game.Players.LocalPlayer
wait(1)
container.Parent = game.Workspace
function startCollecter()
local collected = 0
for i, v in pairs(container:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function(player)
collected = collected + 1
game.Workspace.Sounds.Grabbed.Playing = true
v:Destroy()
local CollectedText = script.Parent
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Containers"
elseif collected == 4 then
CollectedText.Text = "4/15 Containers"
elseif collected == 5 then
CollectedText.Text = "5/15 Containers"
elseif collected == 6 then
CollectedText.Text = "6/15 Containers"
elseif collected == 7 then
CollectedText.Text = "7/15 Containers"
elseif collected == 8 then
CollectedText.Text = "8/15 Containers"
elseif collected == 9 then
CollectedText.Text = "9/15 Containers"
elseif collected == 10 then
CollectedText.Text = "10/15 Containers"
elseif collected == 11 then
CollectedText.Text = "11/15 Containers"
elseif collected == 12 then
CollectedText.Text = "12/15 Containers"
elseif collected == 13 then
CollectedText.Text = "13/15 Containers"
elseif collected == 14 then
CollectedText.Text = "14/15 Containers"
elseif collected == 15 then
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
print("Got it!")
end)
end
repeat wait() until collected == 15
print("Containers were found")
startCollecter()
end
startCollecter()
1 Like
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:04pm
#3
okay, i will try it, thank you
Daronion
(Daronion)
November 10, 2022, 10:05pm
#4
Actually, on a second though. When you click the collected parts, do you delete them? If you delete them, this will not work. You will need to respawn them, but I can help with that as well.
1 Like
CZXPEK
(czo)
November 10, 2022, 10:06pm
#5
Also instead of doing
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Container
...
You could do:
CollectedText.Text = tostring(collected).."/15 Containers"
1 Like
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:07pm
#6
yes, I deleted them, how could I respawn them?
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:07pm
#7
oh alright, this for more short, right?
1 Like
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:14pm
#8
@Daronion
print("Containers were found")
startCollecter()
container:Clone()
container.Parent = game.Workspace
end
startCollecter()
should I try this?
Daronion
(Daronion)
November 10, 2022, 10:37pm
#9
You can try this:
local Players = game.Players.LocalPlayer
wait(1)
container.Parent = game.ReplicatedStorage
function startCollecter()
local container = container:Clone()
container.Parent = workspace
local collected = 0
for i, v in pairs(container:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function(player)
collected = collected + 1
game.Workspace.Sounds.Grabbed.Playing = true
v:Destroy()
local CollectedText = script.Parent
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Containers"
elseif collected == 4 then
CollectedText.Text = "4/15 Containers"
elseif collected == 5 then
CollectedText.Text = "5/15 Containers"
elseif collected == 6 then
CollectedText.Text = "6/15 Containers"
elseif collected == 7 then
CollectedText.Text = "7/15 Containers"
elseif collected == 8 then
CollectedText.Text = "8/15 Containers"
elseif collected == 9 then
CollectedText.Text = "9/15 Containers"
elseif collected == 10 then
CollectedText.Text = "10/15 Containers"
elseif collected == 11 then
CollectedText.Text = "11/15 Containers"
elseif collected == 12 then
CollectedText.Text = "12/15 Containers"
elseif collected == 13 then
CollectedText.Text = "13/15 Containers"
elseif collected == 14 then
CollectedText.Text = "14/15 Containers"
elseif collected == 15 then
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
print("Got it!")
end)
end
repeat wait() until collected == 15
container:Destroy()
print("Containers were found")
startCollecter()
end
startCollecter()
1 Like
DobyTheAnt:
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Containers"
elseif collected == 4 then
CollectedText.Text = "4/15 Containers"
elseif collected == 5 then
CollectedText.Text = "5/15 Containers"
elseif collected == 6 then
CollectedText.Text = "6/15 Containers"
elseif collected == 7 then
CollectedText.Text = "7/15 Containers"
elseif collected == 8 then
CollectedText.Text = "8/15 Containers"
elseif collected == 9 then
CollectedText.Text = "9/15 Containers"
elseif collected == 10 then
CollectedText.Text = "10/15 Containers"
elseif collected == 11 then
CollectedText.Text = "11/15 Containers"
elseif collected == 12 then
CollectedText.Text = "12/15 Containers"
elseif collected == 13 then
CollectedText.Text = "13/15 Containers"
elseif collected == 14 then
CollectedText.Text = "14/15 Containers"
elseif collected == 15 then
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
ok this is a super bad habit, instead you should try this:
if collected < 15 then
CollectedText.Text = tostring(collected).."/15 Containers"
else
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
See much shorter!!!
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 10:47pm
#12
@Daronion the parts that are needed to collect it seems to appear when you clicked, I mean they appear on color gray and when you clicked them it appears normal
here:
Daronion
(Daronion)
November 10, 2022, 10:57pm
#13
Interesting. Can you maybe try this, just a naming change:
local Players = game.Players.LocalPlayer
wait(1)
container.Parent = game.ReplicatedStorage
function startCollecter()
local newContainer = container:Clone()
newContainer.Parent = workspace
local collected = 0
for i, v in pairs(newContainer:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function(player)
collected = collected + 1
game.Workspace.Sounds.Grabbed.Playing = true
v:Destroy()
local CollectedText = script.Parent
if collected == 1 then
CollectedText.Text = "1/15 Containers"
elseif collected == 2 then
CollectedText.Text = "2/15 Containers"
elseif collected == 3 then
CollectedText.Text = "3/15 Containers"
elseif collected == 4 then
CollectedText.Text = "4/15 Containers"
elseif collected == 5 then
CollectedText.Text = "5/15 Containers"
elseif collected == 6 then
CollectedText.Text = "6/15 Containers"
elseif collected == 7 then
CollectedText.Text = "7/15 Containers"
elseif collected == 8 then
CollectedText.Text = "8/15 Containers"
elseif collected == 9 then
CollectedText.Text = "9/15 Containers"
elseif collected == 10 then
CollectedText.Text = "10/15 Containers"
elseif collected == 11 then
CollectedText.Text = "11/15 Containers"
elseif collected == 12 then
CollectedText.Text = "12/15 Containers"
elseif collected == 13 then
CollectedText.Text = "13/15 Containers"
elseif collected == 14 then
CollectedText.Text = "14/15 Containers"
elseif collected == 15 then
game.Workspace.Sounds.Reward.Playing = true
CollectedText.TextColor3 = Color3.new(0, 0.976806, 0)
CollectedText.Text = "15/15 Containers"
wait(2)
CollectedText.Parent:Destroy()
wait(0.01)
local HumanoidRootPart = player.Character.HumanoidRootPart
HumanoidRootPart.CFrame = game.Workspace.End.CFrame
end
print("Got it!")
end)
end
repeat wait() until collected == 15
newContainer:Destroy()
print("Containers were found")
startCollecter()
end
startCollecter()
1 Like
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 11:01pm
#14
okay, i will try it out, thank you
DobyTheAnt
(DobyTheAnt)
November 10, 2022, 11:05pm
#15
@Daronion it still does not work
Daronion
(Daronion)
November 10, 2022, 11:33pm
#16
I see. Unfortunately just from code I can’t tell how this looks within your studio project. If that’s okay with you and there are no privacy issues, you can either send your roblox studio file here, or DM it to me, and I can get it sorted for you
1 Like