I’m actually trying to make a system where if you rightclick on a player, he gets the currently equipped item.
The problem is, that I can’t get rid of this error: “Backpack is not a valid member of Player”
local player = game.Players.LocalPlayer
local Backpack = player.Backpack
local Tool = Backpack.Tool
local mouse = player:GetMouse()
Tool.Equipped:Connect(function()
mouse.Button2Down:Connect(function()
local MouseTarget = mouse.Target
if mouse.Target:FindFirstChild("Humanoid") then
print(mouse.Parent)
end
end)
end)
local player = game.Players.LocalPlayer
local Tool = script.Parent
local mouse = player:GetMouse()
Tool.Equipped:Connect(function()
mouse.Button2Down:Connect(function()
local MouseTarget = mouse.Target
if mouse.Target:FindFirstChild("Humanoid") then
print(MouseTarget.Name)
end
end)
end)
local player = game.Players.LocalPlayer
local Tool = script.Parent
local mouse = player:GetMouse()
local isEquipped = false
Tool.Equipped:Connect(function()
isEquipped = true
end)
Tool.Unequipped:Connect(function()
isEquipped = false
end)
mouse.Button2Down:Connect(function()
if isEquipped == true then
local MouseTarget = mouse.Target
if MouseTarget ~= nil then
print(MouseTarget)
end
end
end)
Backpack might not be available immediately when the script runs. Using WaitForChild might have solved the issue, but it looks like you figured it out anyway.