title might be confusing but, i'm making a button that gives you a weapon on a certain level, but to avoid taking up room in the backpack, i need it to delete the previous gear, or all gears before placing the new gear down, the thing i really need help with is how to get all the tools in the players backpack, i don't really know how to define that.
Here is my current Script
Points = 10
Stat = "Points"
Give = script.Parent
Backup = Give:Clone()
function onTouched(hit)
if hit.Parent.Humanoid~= nil then
local Plr = game.Players:findFirstChild(hit.Parent.Name)
if Plr ~= nil then
local StatLocal = Plr.leaderstats:findFirstChild(Stat)
if StatLocal ~= nil then
if StatLocal.Value >= Points then
local Check = Plr.StarterGear:findFirstChild(script.Parent.Name)
if Check == nil then
StatLocal.Value = StatLocal.Value - Points
local W1 = Backup:Clone()
local W2 = Backup:Clone()
W1.Parent = Plr.Backpack
W2.Parent = Plr.StarterGear
end
end
end
end
end
end
script.Parent.Parent.Touched:connect(onTouched)
this script does the job of putting the weapon in your backpack AND Starterpack, so if you die, you'll get the weapon back

10 comments
where do i put the
Local Functionbit? and where do i put the The `DestroyChildren()'For some reason this wont work, the output says that Line 2 of your example is wrong, wherever i put the function and when it fires, is it wrong? Is it because the script is inside the gear that given when the button is pressed
The script should be inside ServerScriptService. The DestroyChildren() function should be prior to your main script and then called in your main script right before you add new gear.
Why do i still not get this?
is this got to do with remoteEvents?
because i dont do well with events
could you maybe re-write this, because im confused, putting the script in serverscriptservice just makes it 10x worse as the regular script is trying to get the parent (which is the gear), and your saying to put the function into a new script(?, or not), or to put the main script inside serverscriptservice, i feel like reposting the question
Send me a message on Roblox with your Discord and I'll walk you through step by step. Afterwords I'll update the answer with what we accomplished.
ok
you are a very good teacher