function Player()
local ray = Ray.new(Root.Parent.Head.Position,(Root.Parent.Head.CFrame.LookVector).unit*5000)
local hit, position = game.Workspace:FindPartOnRay(ray)
local playerList = game.Players:GetChildren()
if hit ~= nil then
local Thing = hit.Parent
if Thing.ClassName ~= "Accessory" then
for i, v in pairs(playerList) do
local playerLST = playerList[i]
print (playerLST)
print (Thing.Name)
if Thing.Name == playerLST then
local distance = (hit.Position - Root.Parent.Head.Position).magnitude
print(distance)
end
end
end
end
end
✓ ANSWER ACCEPTED
the if thing.name == playerLST then are the same but isnt activating?
1 answer
✓ Accepted answer
function Player()
local ray = Ray.new(Root.Parent.Head.Position,(Root.Parent.Head.CFrame.LookVector).unit*5000)
local hit, position = game.Workspace:FindPartOnRay(ray)
local playerList = game.Players:GetChildren()
if hit ~= nil then
local Thing = hit.Parent
if Thing:IsA("Accoutrement") ~= true then
for i, v in pairs(playerList) do
local playerLST = v
print (playerLST)
print (Thing.Name)
if Thing.Name == playerLST.Name then
local distance = (hit.Position - Root.Parent.Head.Position).magnitude
print(distance)
end
end
end
end
end
You were trying to compare a String to an Object. The fix was simply to add a .Name after playerLST.
If this helped, make sure to upvote/accept it! Thanks!
1 comment
0
Thanks it worked i cant upvote (i dont have any reputation) but i would if i could
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
put the code inside a code block please
there
if thing.Name == v then
nope
yep