Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

the if thing.name == playerLST then are the same but isnt activating?

  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	

5 comments

0

put the code inside a code block please

0

there

0

if thing.Name == v then

0

nope

0

yep

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.