Basically I want the script to check if there is any parts in the folder that players have called “bag”, and if there is parts then it will check the “IntValue” number of each part and add it up. After the amount is all added up the parts get deleted and the player receives the money from the added amount.
Here is the script I have so far… but I probably will have to tune it a bit.
– I may need to add more here but i’m not sure what i will add yet…
local prox = script.Parent --proximity prompt of Sell part
local player = game:GetService(‘Players’) – gets the “game.players” folder
local plr = player.LocalPlayer – maybe gets the local player so it only takes the players part who sells
local bag = plr:WaitForChild(“bag”) – looks for the folder called “bag” from the player
– not sure what to code here…
prox.Triggered:Connect(function()
if bag:GetChildren() ~= nil then
Here’s how you can modify your script to check if the player has parts in their “bag” folder and add up their “IntValue” numbers:
local prox = script.Parent --proximity prompt of Sell part
local player = game:GetService("Players") -- gets the "game.players" folder
local plr = player.LocalPlayer -- gets the local player so it only takes the parts from the player who sells
local bag = plr:WaitForChild("bag") -- looks for the folder called "bag" from the player
-- check if the "bag" folder has any children (i.e. parts)
prox.Triggered:Connect(function()
if #bag:GetChildren() > 0 then
-- initialize a variable to store the total value of the parts
local totalValue = 0
-- loop through all the parts in the "bag" folder
for _, part in pairs(bag:GetChildren()) do
-- check if the part has an "IntValue" property
if part:IsA("IntValue") then
-- add the value of the "IntValue" property to the total value
totalValue = totalValue + part.Value
end
end
-- delete the parts from the "bag" folder
bag:ClearAllChildren()
-- give the player the money for the parts
plr.Money.Value = plr.Money.Value + totalValue
end
end)
This script checks if the “bag” folder has any children (i.e. parts), and if it does, it loops through all the parts and adds up the value of their “IntValue” properties. Then it deletes the parts from the “bag” folder and gives the player the total value of the parts as money.
Local IntMath = 0
for p8, g10 in pairs(ButtonsFrame:GetDescendants()) do
if g10:isA("Folder") then
for p9, g11 in pairs(G10:GetDescendants()) do
if g11.Name == "Bag" then
IntMath = IntMath + g11.IntValue
g11:Destroy()
end
end
end
end
I’m not sure what to code here…
prox.Triggered:Connect(function()
if bag:GetChildren() ~= nil then
end
end)
Can anyone help?
Edit: I have fixed my script issue.
However now I am having an issue with the part deleting…
Here is my script for the part of deleting the part, but it is not working…
money:GetChildren(“Humanoid”).Value <= 0 then – checks the intvalue of the part
part:Destroy() – destroys the part
This should work, I am not sure if this is what you are looking for but I hope it helps! local player = script.Parent
local bag = player.Parent
local total = 0
for i,v in pairs(bag:GetChildren()) do
total = total + v.IntValue
end