Problem with ~=

So im making a sword system. And when a player clicks a tool it prints all player names except his name.
i tried this but it doesnt work.

-- Variables 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WeaponStats = require(ReplicatedStorage:WaitForChild("WeaponStats"))
local DistanceModule = require(ReplicatedStorage:WaitForChild("DistanceModule"))

-- Player
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")


-- Tool
local Tool = script.Parent
local AnimationsAction = Tool.ActionAnimations:GetDescendants()
local Sounds = Tool.Sounds:GetDescendants()

local EventBlock = Tool.BlockingEvent
local Event = Tool.Event



Tool.Activated:Connect(function()
	for i,v in pairs(Players:GetPlayers()) do
		if v.Parent:FindFirstChild("HumanoidRootPart") ~= HumanoidRootPart then
			print(v)
		end
	end
end)

Right now v = a Player and the parent of a Player is Players. (game.Players) so what you’d want your code to look like is something like this below since right now Im confused what you are trying to do.

Tool.Activated:Connect(function()
	for i,v in pairs(Players:GetPlayers()) do
		if v.UserId ~= Player.UserId then
			print(v)
		end
	end
end)

Would this work with the humanoidrootpart because i want to get a players humanoid.

To print all player names except your player name you can do:

Tool.Activated:Connect(function()
	for i,v in pairs(Players:GetPlayers()) do
		if v.Name ~= Player.Name then
			print(v.Name)
		end
	end
end)

Ok, both of them work but who do i give the solution too?

If you want to get the HumanoidRootPart of the players that are NOT the main player then what you’d want to do is just add this v.Character:FindFirstChild("HumanoidRootPart") as this will get you the HumanoidRootPart. Along with the code above.

Give it to Nexcon, since he replied first.

1 Like