So I have started to work on the player tools in my game, and I would like them to load into the Backpack after my loading screen has been done loading. The script works fine, but I have run into a problem which I do not understand. When the script gives the tools, it runs the for loop twice (I get x2 the gears that I’m supposed to get).
Here is my code for the tool giving:
for a, Item in pairs(Player.PlayerItems:GetChildren()) do
wait()
if Item.Innocent.Value == true then
Item:Clone().Parent = Player.Backpack
end
end
Innocent is a value which I have added to all items. It indicates if the tool should be given or not inside the lobby (If it’s false, then it’s harmfull to other players and the lobby). Player is a local variable created in the begining of the script.
for a, Item in pairs(Player.PlayerItems:GetChildren()) do
print(a)
print(Item)
wait()
if Item.Innocent.Value == true then
Item:Clone().Parent = Player.Backpack
end
end
local Player = game.Players.LocalPlayer
local LoadingText = script.Parent.Background.LoadingText
local Frame = script.Parent.Background
repeat wait()
LoadingText.Text = "Loading" .. "."
wait(0.5)
LoadingText.Text = "Loading" .. ".."
wait(0.5)
LoadingText.Text = "Loading" .. "..."
wait(0.5)
until game:IsLoaded()
LoadingText.Text = "Done Loading!"
wait(3)
Frame:TweenPosition(UDim2.new(1.1, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint)
Player.InLoadingScreen.Value = false
for i = 1, 50 do
wait(0.01)
for _, Music in pairs(workspace.GameSounds:GetChildren() and workspace.GameSounds:GetDescendants()) do
if Music:IsA("Sound") then
Music.Volume = Music.Volume + 0.01
end
end
end
for a, Item in pairs(Player.PlayerItems:GetChildren()) do
print(a)
print(Item)
wait()
if Item.Innocent.Value == true then
Item:Clone().Parent = Player.Backpack
end
end
wait(1)
game.ReplicatedStorage.SetPlayerStat:FireServer(Player.InLoadingScreen.Value, false)
script.Parent:Destroy()
The script is basically the gui while it’s loading, then when it’s done, it turns up the game volume. None of it should affect the script I believe?
ok I dont see a problem here. There might be a chance u have duplicated scripts, search all the scripts in explorer, also if the script is located inside of the tool, then its obviously cloned
The folder is created when the player joins by PlayerAdded script. The content is filled by a playerscript which checks what items the person own when it has joined.