How to make the item only go to a player once

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)

Why are you using a RemoteEvent for that?

EDIT: Im not even sure what you are doing. Please explain better.

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”)

game.ReplicatedStorage.InventoryJoin:FireServer(players, inventory, equipped)

I think you should not do that with a RemoteEvent

EDIT: Gimme a sec Imma see a good way on how to do this.

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

Okay, I’ll try it out hopefully it works

I made a mistake.

Please change

if ServerStorage.Tools:WaitForChild(tostring(EquippedItem.Value)) then

to

if ServerStorage.Tools:FindFirstChild(tostring(EquippedItem.Value)) then
1 Like