Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if backpack slot is used?

Asked by 5 years ago
Edited 5 years ago

so i made this script for a store and i want to check if there is already a tool taking up a backpack slot

script so far:

local player = game.Players.LocalPlayer
points = player.leaderstats.Coins

local product = ".300 Carbine"
local prodlocation = game.ServerStorage.NewWeaponStache.Carbines -- remember to change this last part later
-----------------------------------------------------------------------------------------

function activate()
if points >= script.Parent.Parent.Price.Text then
prodlocation:Clone().Parent = player.Backpack
prodlocation:Clone().Parent = player.StarterGear
end
end


script.Parent.MouseButton1Click:Connect(activate)

but when the weapon gets put into the players inventory, how do i check before that (overexaggeration) so the player can freely switch their weapons without overload of like 58+ weapons

0
if player.Backpack:FindFirstChild(product) then DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

I don't know if this will work, I will test it when I have a chance later. And this should basically like replace the item that is already in the players backpack with the item they bought.

local player = game.Players.LocalPlayer
points = player.leaderstats.Coins
Tool = false
local product = ".300 Carbine"
local prodlocation = game.ServerStorage.NewWeaponStache.Carbines -- remember to change this last part later
-----------------------------------------------------------------------------------------

function activate()
if points >= script.Parent.Parent.Price.Text then
If Tool = false then 
prodlocation:Clone().Parent = player.Backpack
prodlocation:Clone().Parent = player.StarterGear
Tool = true
Elseif points >= script.Parent.Parent.Price.Text then
If Tool = true then
local tool = playet.Backpack:GetChildren
If tool then 
tool:Destroy
Tool = false
prodlocation:Clone().Parent = player.Backpack
prodlocation:Clone().Parent = player.StarterGear
Tool = true
end
end


script.Parent.MouseButton1Click:Connect(activate)

Once again this is by guess. So I will get on pc in few and check. And if it doesn't work, I will make sure to make a work in script

Otherwise if just wanting to check for a tool like you asked. You can create a for loop checking for tools within in the player constantly.

for _,v in pairs(player.Backpack:GetChildren()) do
    if v:IsA("Tool") then -- finds tool or tools
   -- script whatever happens after a tool is found
    end
end

0
thx bro helped alot speedyfox66 237 — 5y
0
ill do some fixing of this later becuz theres some errors but its fine speedyfox66 237 — 5y
0
Ok, I can fix the errors in a minute. If you want. ChefDevRBLX 90 — 5y
Ad

Answer this question