I am making create a class menu gui. I have tools in replicated storage but i dont know how to script it so that when a player clicks on the text button, the weapon is in the backpack. Also how would I script a different button that would remove all the selected weapons? This is my code so far. I know it not much. it is incomplete and btw kf5dot is the name of one of the weapons.
function Click(mouse) local KF5Dot = game.ReplicatedStorage: end
Let's disregard what you did because your script is heavily incomplete, no call is being taken place, plus this is not how you'd activate the function by pressing a ScreenGui.
I do Not know you hierarchy, so I cannot say my script will go to the correct places, but I'll make it so you need to put it inside of the TextButton.
This is to be for a LocalScript ! Make sure the tools are inside of 'ReplicatedStorage' ! Look bellow this script for information!
sp = script.Parent player = game.Players.LocalPlayer sp.MouseButton1Click:connect(function() local KF5Dot = game.ReplicatedStorage:FindFirstChild("KF5Dot"):Clone() KF5Dot.Parent = player.Backpack end)
Due to this being a LocalScript, we can use LocalPlayer which is pretty helpful. Now, doing KF5Dot.Parent =
will assign where this clone is going to, in this case, the players Backpack.
Now, to clear our the tools in the Backpack, you'd do this script (Still a LocalScript inside of a TextButton)
sp = script.Parent player = game.Players.LocalPlayer sp.MouseButton1Click:connect(function() local All_Tools = player.Backpack:GetChildren() for _, Tool in pairs(All_Tools) do Tool:remove() end end)
This script is going through each item in your backpack using a Generic For loop, then removing them. for _,Tool
- Tool is actually going to be the Tool in backpack, which is why I did Tool:remove()
!
Get a local script and put it in the button and put this in the local script :3
player = game.Players.LocalPlayer function click() weapon = game.ReplicatedStorage:FindFirstChild("WeaponNameHere"):clone() weapon.Parent = player.Backpack end script.Parent.MouseButton1Click:connect(click)