How do i make a this script only give gear one time

Im trying to make it so the players can only get one gear but im not sure how to do that

game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
	if player:WaitForChild("Data").Minutes.Value >= itemMins then
		local newItem = item.Parent:Clone()
		newItem.Parent = player.Backpack
		newItem.Handle.Anchored = false
	else
		player.PlayerGui.ScreenGui.Error.Visible = true
		wait(0.5)
		player.PlayerGui.ScreenGui.Error.Visible = false
		print(itemMins)
		print(item.Name)
		
		
	end
end)

Do you know what the name of the tool is?

Are you sure you’re referencing the newItem variable correctly? Do consider print statements for your variables :thinking:

All of it works im just trying to make it not giving the player the same item over and over again

yes, another script prints the item’s name

Just simply check the Player’s Backpack/Player’s Character has the tool, then run your code if it doesn’t

Yup, I was going to modify your script for you but I need to know the name of the Tool so I can see if the player already has it.

should i use iv loops? to loop through the folder and check if the player has the tool or not?

how about this

local l = 0 
game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
        if  l == 0 then
	      if player:WaitForChild("Data").Minutes.Value >= itemMins then
		   local newItem = item.Parent:Clone()
		   newItem.Parent = player.Backpack
		   newItem.Handle.Anchored = false
                   l ==1
	    else
		   player.PlayerGui.ScreenGui.Error.Visible = true
		    wait(0.5)
		    player.PlayerGui.ScreenGui.Error.Visible = false
		   print(itemMins)
		   print(item.Name)
	
		
	   end

end)

You could just say

if not backpack:FindFirstChild("ToolName")

Nah, you can just simply do this:

game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
    print(player)
    print(item.Parent)
    print(itemMins)

	if player:WaitForChild("Data").Minutes.Value >= itemMins and player.Backpack:FindFirstChild(newItem) == nil and player.Character:FindFirstChild(newItem) == nil then
		local newItem = item.Parent:Clone()
		newItem.Parent = player.Backpack
		newItem.Handle.Anchored = false
	else
		player.PlayerGui.ScreenGui.Error.Visible = true
		wait(0.5)
		player.PlayerGui.ScreenGui.Error.Visible = false
		print(itemMins)
		print(item.Name)
		
		
	end
end)
1 Like

That would check if 1 is equal to 1, to set the value you would do 1 = 1.

my bad it should be l = 1 or l += 1

No worries! Just wanted to make sure it wouldn’t break the script because I’ve done things like that before and spent hours debugging.

It just keeps on cloning itself everytime i spam click it

Not sure, I can’t test right now.

Really? Could you try the script again? I added a couple more prints

you can try my or if player can get this tool from other script try @JackscarIitt solution

local l = 0 
game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
        if  l == 0 then
	      if player:WaitForChild("Data").Minutes.Value >= itemMins then
		   local newItem = item.Parent:Clone()
		   newItem.Parent = player.Backpack
		   newItem.Handle.Anchored = false
                   l = 1
	    else
		   player.PlayerGui.ScreenGui.Error.Visible = true
		    wait(0.5)
		    player.PlayerGui.ScreenGui.Error.Visible = false
		   print(itemMins)
		   print(item.Name)
	
		
	   end

end)

you didn’t check starterGear
limit

I don’t think that that would work because the error message may not show if the tool is not in the player’s backpack but the timer is not up.