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

Why does using == on 2 clearly same variables not work?

Asked by 2 years ago

Im working on a party system, and it is not saying these two variables are the same. I have also tried using lists, and that did not work. (The player ids are negative because I am using a local server.)

local parties = game.ReplicatedStorage.Parties

game.Players.PlayerAdded:Connect(function(plr)
    local party = Instance.new('BoolValue', parties)
    party.Name = plr.UserId
end)

game.ReplicatedStorage.Remotes.Notify.OnServerEvent:Connect(function(plr, client)
    game.ReplicatedStorage.Remotes.Notify:FireClient(client, 'join', plr)
end)

game.ReplicatedStorage.Remotes.JoinParty.OnServerEvent:Connect(function(plr, client)
    game.ReplicatedStorage.Remotes.Notify:FireClient(client, 'joined', plr)
    game.ReplicatedStorage.Remotes.Notify:FireClient(plr, 'joined', client)
    print('Joined ' .. client.Name .. "'s party!")
    for i,v in ipairs(parties:GetChildren()) do
        print(v.Name, plr.UserId, client.UserId)
        if v.Name == plr.UserId then
            v:Destroy()
            print('hey')
        end
        if v.Name == client.UserId then
            local uip = Instance.new('BoolValue',v)
            uip.Name = plr.UserId
            print('pls work')
        end
    end
end)

the print(v.Name, plr.UserId, client.UserId) returns -1 -2 -1, and for the second player it returns -2 -2 -1, Yet 'hey' or 'pls work' are not printing in the console, and the objects are not created correctly.

1 answer

Log in to vote
0
Answered by 2 years ago

v.Name is a string, plr.UserId is a number. They are two completely different types of values. To do what you wanted to do, you have to do

if tonumber(v.Name) == plr.UserId then
           v:Destroy()
           print('hey')
end

Hope this helped.

Ad

Answer this question