This script works perfectly,but when it’s collected,and after 30 seconds comes back,you can’t collect it,and the script stops working.
Here is the script:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
player.PlayerGui.kanictra.button.MouseButton1Click:Connect(function()
player.PlayerGui.qusrt.Enabled = true
player.PlayerGui.kanictra.button.Visible = false
if player.PlayerGui.qusrt.TextLabel.Text == "9/10" then
player.PlayerGui.qusrt.TextLabel.Text = "10/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "8/10" then
player.PlayerGui.qusrt.TextLabel.Text = "9/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "7/10" then
player.PlayerGui.qusrt.TextLabel.Text = "8/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "6/10" then
player.PlayerGui.qusrt.TextLabel.Text = "7/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "5/10" then
player.PlayerGui.qusrt.TextLabel.Text = "6/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "4/10" then
player.PlayerGui.qusrt.TextLabel.Text = "5/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "3/10" then
player.PlayerGui.qusrt.TextLabel.Text = "4/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "2/10" then
player.PlayerGui.qusrt.TextLabel.Text = "3/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "1/10" then
player.PlayerGui.qusrt.TextLabel.Text = "2/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
elseif player.PlayerGui.qusrt.TextLabel.Text == "0/10" then
player.PlayerGui.qusrt.TextLabel.Text = "1/10"
script.Parent.Parent.Parent = game.ReplicatedStorage.collectedkanictras
end
end)
end)
end)
it’s because after the collectible was collected and moved to replicatedstorage there was nothing to bring it back to the work space and reset its state
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function updateCounter(textLabel)
local current = tonumber(textLabel.Text:match("(%d+)/10"))
local new = math.min(current + 1, 10)
textLabel.Text = new .. "/10"
return new == 10
end
local function setupCollectible(player)
local kanictra = player.PlayerGui:WaitForChild("kanictra")
local button = kanictra:WaitForChild("button")
local qusrt = player.PlayerGui:WaitForChild("qusrt")
button.MouseButton1Click:Connect(function()
player.PlayerGui.qusrt.Enabled = true
player.PlayerGui.kanictra.button.Visible = false
if updateCounter(qusrt.TextLabel) then
button.Parent.Parent = ReplicatedStorage.collectedkanictras
end
task.delay(30, function()
button.Parent.Parent = workspace
button.Visible = true
qusrt.Enabled = false
end)
end)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
setupCollectible(player)
end)
end)
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
setupCollectible(player)
end)
end
there are others scripts to put it into the replicated storage
like when an entity hits you,you lose every gas can you have collected,and set them back to their spawn location
and exactly after that,you can’t collect them again.
please provide the code of the other scripts
print("waiting for player...")
local player = game.Players:GetChildren()[1]
local hui = game.ReplicatedStorage.collectedkanictras
print("player is here!!!11")
script.Parent.hitpart.Touched:Connect(function(hit)
print("JUST PRINT SOMETHING ALREADY")
while wait(0.1) do
print("smth")
if workspace:FindFirstChildOfClass("Model") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:WaitForChild("Humanoid").WalkSpeed == 13 then
print("aaaa")
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 2.75
if hui:FindFirstChildOfClass("Folder") then
if hui:FindFirstChild("kanictra10") then
hui:FindFirstChild("kanictra10").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra9") then
hui:FindFirstChild("kanictra9").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra8") then
hui:FindFirstChild("kanictra8").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra7") then
hui:FindFirstChild("kanictra7").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra6") then
hui:FindFirstChild("kanictra6").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra5") then
hui:FindFirstChild("kanictra5").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra4") then
hui:FindFirstChild("kanictra4").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra3") then
hui:FindFirstChild("kanictra3").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra2") then
hui:FindFirstChild("kanictra2").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
elseif hui:FindFirstChild("kanictra1") then
hui:FindFirstChild("kanictra1").Parent = workspace.parts
player.PlayerGui.qusrt.TextLabel.Text = "0/10"
else
print("no gas cans found.")
end
else
return
end
else
return
end
end
end)
This is the script of the entity’s hitpart,which sets all gas cans back,when is touched(ignore prints)