When “SworsSlotEquipped” button is press, I want to equip in hand the tool in Backpack instead of having to click on the Backpack tool at the bottom of screen, and also for “SwordSlotUnequipped” to put the tool away
Also I every time I click to equipped on my gui I made it keeps giving me a Sword each time I click the button, I only want one. I’m guessing it has something to do with the remote event but I’m sure how to stop it.
local gui = game:GetService(“StarterGui”)
local item = script.Parent
local tool = game.ReplicatedStorage.ClassicSword
local purchased = script.Parent.Price
local swordSlotEquipped = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame.InventoryScrollingFrame.InventoryVPFrame.SwordSlotEquipped
local swordSlotUnequipped = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame.InventoryScrollingFrame.InventoryVPFrame.SwordSlotUnequipped
local function equipPurchasedItem()
if purchased.Text == “Equip” then
swordSlotUnequipped.Visible = true
swordSlotEquipped.Visible = false
purchased.Text = “Unequip”
print(“Nice new shinny sword!”)
game.ReplicatedStorage.RemoteEvents.SwordRE:FireServer()
end
end
local function unequipPurchasedItem()
if purchased.Text == “Unequip” then
swordSlotEquipped.Visible = true
swordSlotUnequipped.Visible = false
print(“Let’s Fight!”)
end
end
item.MouseButton1Click:Connect(equipPurchasedItem)
item.MouseButton1Click:Connect(unequipPurchasedItem)
1 Like
Just in case I’m not understanding you correctly, you want to Equip a tool which is in the backpack?
You can do so with the following:
Character.Humanoid:EquipTool(TheRefrenceToTheToolInTheBackpack)
For putting the tool away, you’ll need to find the tool in the character and set the parent of the tool to the players backpack. If you want me to deep dive into your code a little bit more, I’m going to need both the server script as well as the client script for this, preferably in a code block.
1 Like
Ok i them within the hour I’m AFK, thank you
this is the ServerScriptService script “SwordRE”
local tool = game.ReplicatedStorage.ClassicSword
local originalClone = tool:Clone()
game.ReplicatedStorage.RemoteEvents:WaitForChild("SwordRE").OnServerEvent:Connect(function(Player)
originalClone:Clone().Parent = Player.Backpack
end)
The script I posted up top is the client
So, the following are your issues according to the post:
- It’s not auto equipping.
- You only want one sword.
- You want it to unequip as well.
Before you use this code I want to make it 100% clear that although this works, there are more efficient ways to do what I’m doing here. Personally I’d recommend using my script here as a guide and then changing stuff to make it cleaner and more efficent. I really just copy and pasted your script and made changes to fit your criteria here.
Keep in mind, I made this under the assumption that purchased.Text
in the LocalScript can only be two values, Equip or Unequip. I’d recommend using elseif instead if it can be more than just those two.
Try the following for the server.
local tool = game.ReplicatedStorage.ClassicSword
local originalClone = tool
game.ReplicatedStorage.RemoteEvents:WaitForChild("SwordRE").OnServerEvent:Connect(function(Player)
if Player.Character:FindFirstChild("ClassicSword") then return end
if Player.Backpack:FindFirstChild("ClassicSword") then
Player.Character.Humanoid:EquipTool(Player.Backpack.ClassicSword)
else
originalClone:Clone().Parent = Player.Backpack
Player.Character.Humanoid:EquipTool(Player.Backpack.ClassicSword)
end
end)
Try the following for the Client
local gui = game:GetService("StarterGui")
local item = script.Parent
local tool = game.ReplicatedStorage.ClassicSword
local purchased = script.Parent.Price
local swordSlotEquipped = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame.InventoryScrollingFrame.InventoryVPFrame.SwordSlotEquipped
local swordSlotUnequipped = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame.InventoryScrollingFrame.InventoryVPFrame.SwordSlotUnequipped
item.MouseButton1Click:Connect(function()
if purchased.Text == "Equip" then
swordSlotUnequipped.Visible = true
swordSlotEquipped.Visible = false
game.ReplicatedStorage.RemoteEvents.SwordRE:FireServer()
else
swordSlotEquipped.Visible = true
swordSlotUnequipped.Visible = false
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
end)
1 Like
works good enough for me, thank you so much!
would it be smarter to put the server script into a Module script as a table so when i add more items later on, or should I keep it the way I have it?
1 Like