So I made a script to make it so when a player joins they get an item and they do but when another player joins the other player gets the item again so i need help with that. Here is the script:
game.Players.PlayerAdded:Connect(function()
game.ReplicatedStorage.InventoryJoin.OnServerEvent:Connect(function(player, players, inventory, equipped)
local item = equipped.Value
local itemsomething = script.Parent.Parent.ServerStorage.Tools:FindFirstChild(tostring(item))
local idk = itemsomething:Clone()
idk.Parent = inventory
end)
end)
So, I am making a shop and I am making it so whenever a player joins they get the item they equipped and I have the local script here:
local players = script.Parent.Parent.Name
local inventory = script.Parent.Parent:WaitForChild(“Backpack”)
local equipped = script.Parent.Parent:WaitForChild(“Equipped”)
local ServerStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(Player)
local Flags = Instance.new("Folder",Player)
Flags.Name = "Flags"
local EquippedItem = Instance.new("StringValue",Flags)
EquippedItem.Name = "EquippedItem"
if ServerStorage.Tools:WaitForChild(tostring(EquippedItem.Value)) then
local Tool = ServerStorage.Tools:FindFirstChild(tostring(EquippedItem.Value))
Tool:Clone().Parent = Player.Backpack
else
-- Make a Default item if wanted.
end
end)
What this is doing is as soon as the player joins it adds a Folder and a StringValue called “EquippedItem” to the player and checking if the EquippedItem value is somewhere inside the “Tools” Folder in server storage. then cloning it to the players Backpack