How can i use isA() to check if a variable is a player

so if i have a variable like

local player = "1BL1ZZARD"
local fruit = "Apple"

if player:IsA("Player") then
   print("hi player!")
end

if fruit:IsA("Player") then
   print("hi player!")
end

how can i accomplish something like this?
in addition, if it is a player, how can i do something like??

player:Kick()
-- or
player.Humanoid.Health = 0

Probably not the best way to do something like this but…

if game:GetService('Players'):FindFirstChild(tostring(fruit), false) then
    print('hi player!')
end

hey, i’ve updated the post a little bit, can you please check that out?

if game:GetService('Players'):FindFirstChild(tostring(fruit), false) then
    local plr = game:GetService('Players'):FindFirstChild(tostring(fruit), false)
    local char = plr.Character or plr.CharacterAdded:Wait()
    local humanoid = char:FindFirstChild('Humanoid') or char:WaitForChild('Humanoid', 10)

    if (humanoid) then
        humanoid.Health = 0
    end

    plr:Kick('Message')
end
2 Likes

If you’re checking if the variable itself is a reference to a player:

if typeof(var) == "Instance" and var:IsA("Player") then
   -- Checks if the variable is an instance, then use the IsA method on it 
   --...
end

If you’re checking if a variable would lead to a valid player:

local plr = game:GetService("Players"):FindFirstChild(var)

if plr then
   -- Check if the plr variable leads to a valid player
   -- plr is now a reference to the Player
   --...
end
2 Likes
local player = "1BL1ZZARD"

if game.Players:FindFirstChild(player) then
    print("hi player!")
end
1 Like

Try

local player = "1BL1ZZARD"
local fruit = "Apple"
local Players = game:GetService("Players") -- Gets the players folder


if i, v in pairs(Players:GetChildren()) do -- Gets everything in the players folder
     if v.Name == player then -- Checks for everything with the value of the var "player"
          v:Kick("Reason for kick") -- kicks the player
          -- v.Humanoid.Health = 0 -- kills the player
          print("hi player")
     end
end

if i, v in pairs(Players:GetChildren()) do
     if v.Name == fruit then
          v:Kick("Reason for kick")
          -- v.Humanoid.Health = 0
          print("hi player")
     end
end
1 Like

I wouldn’t necessarilly do a recursive search for this one, :FindFirstChild() should be enough for this one.

Unless we are trying to convert all of the players names to lowercase and the string to lowercase to get the exact player with no case sensitivity

Thanks everyone, since @Inf_idel was the first one to give a response that works, the solve goes to them.

I’ll give everyone who tried helping a like.