Why does this script not work?

local Char = game.Players.LocalPlayer.Character
local Plr = game.Players.LocalPlayer
local Hum = Char:WaitForChild("Humanoid")
local Backpack = Plr.Backpack
local Tools = Backpack:FindFirstChildOfClass("Tool")
local Sword = script.Parent
local Gun = Backpack.Gun


Sword.Unequipped:Connect(function()
	if Tools then
		Gun.Parent = Char
		Gun.Equipped = true
		Sword.Unequipped = true
	end
end)

if a player unequips the sword the gun should be equipped but if i run it all it gives me is Equipped is not a valid member of tool even though the script works fine? i need help bruh

2 Likes

A better approach:

local Char = game.Players.LocalPlayer.Character
local Plr = game.Players.LocalPlayer
local Hum = Char:WaitForChild("Humanoid")
local Backpack = Plr.Backpack
local Tools = Backpack:FindFirstChildOfClass("Tool")
local Sword = script.Parent
local Gun = Backpack.Gun

Sword.Unequipped:Connect(function()
	if Tools then
		Hum:UnequipTools()
		Hum:EquipTool(Gun)
	end
end)
2 Likes

now its giving me maximum event re-entrancy depth (80)

1 Like

never mind i am infact stupid i fixed it now thank you so much

1 Like
local Char = game.Players.LocalPlayer.Character -- ??
local Plr = game.Players.LocalPlayer -- !?
local Hum = Char:WaitForChild("Humanoid")
local Backpack = Plr.Backpack
local Tools = Backpack:FindFirstChildOfClass("Tool") -- Why?
local Sword = script.Parent
local Gun = Backpack.Gun

Sword.Unequipped:Connect(function()
	if Tools then
		Hum:UnequipTools()
		Hum:EquipTool(Gun)
	end
end)
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
local Backpack = Plr.Backpack
local Sword = script.Parent
local Gun = Backpack:FindFirstChild("Gun")

Sword.Unequipped:Connect(function()
	if Gun then
		Hum:EquipTool(Gun)
	end
end)
2 Likes

That’s great. Glad I could help.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.