Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago
  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 
0
put the code inside a code block please Le_Teapots 913 — 5y
0
there CrimSint -3 — 5y
0
if thing.Name == v then Gey4Jesus69 2705 — 5y
0
nope CrimSint -3 — 5y
0
yep Gey4Jesus69 2705 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
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!

0
Thanks it worked i cant upvote (i dont have any reputation) but i would if i could CrimSint -3 — 5y
Ad

Answer this question