Hello, so I have a button players can press to give them a football. But the issue is that they can spam and have like a million of them. The button works fine, just is there any way I can limit a players inv to having 1 football. A way where if a player has a football, the button recognizes it and does not let them have another.
Check if they have the item, try creating a table, and inserting the football inside, when clicking check if the Item is inside the table, if yes, it wont do anything, if no, it will give it.
This is common thing people do to check if they have an item, like if you bought a one time thing, like a gun, why would you buy the same gun again if you already have it?
To Prevent people from buying the item again, we will check if they have it by checking there items, if its found, we won’t give it to them, if it isn’t, we will, we will use table.find() for this:
OwnedItems = {}
btn.Activated:Connect(function()
if table.find(OwnedItems, Football) then
return
else
table.insert(OwnedItems, Football) -- do this on the Server, not the Client
return give:FireServer()
end
end)
I would Recommend setting this up for each Player if you want them to have the same item, if you want them to share, them this would work, do this on the Server, Exploiters can easily exploit this if on the Client
You could also check if the player has the football, seems like the ball is a TOOL then you should check if the ball is on his backpack or Character then if its true dont run the code
The simplest way of doing this is checking if the backpack has a football, and if it does, it won’t fire the server.
local player = game.Players.LocalPlayer
btn.MouseButton1Click:Connect(function()
if not player.Backpack:FindFirstChild("Football") then -- checks if there isn't a football
give:FireServer()
end
end)
However, WARNING, you should probably also ALWAYS put as check on the server as well, otherwise exploiters can fire the event anyway. Something like this:
game.ReplicatedStorage.GiveFootBall.OnClientEvent:Connect(function(player)
if not player.Backpack:FindFirstChild("Football") then -- checks if there isn't a football
-- code that gives football
end
end)
It would go in the same place you screenshotted.
Also, @DasKairo is right. If the player is holding the item, the tool would no longer be in the backpack, but instead the character. You would also have to place a check on the character to see if “Football” is inside the character. Something like this:
-- checks if football isn't in the backpack AND isn't in the character
if not player.Backpack:FindFirstChild("Football") and not player.Character:FindFirstChild("Football") then
This system might work for what he is trying to do, but what you have is a simple system, if you want a Inventory as in you cant get an item again, this would work for that
@develofied In that case, both codes should work, @1nicopatty’s code would work the best if so