I’m making this bounty system for a game. When the player goes up to an npc and interacts with it, it chooses a random player in the server to be the “target”. I don’t want it to chose the player itself tho.
local Players = game.Players:GetPlayers()
local nplrs = #Players
local Randomplayer = nil
repeat
wait(0.01)
if nplrs > 0 then
Randomplayer = Players[math.random(1, nplrs)]
end
print(Randomplayer)
until Randomplayer ~= Player.Name
print(Randomplayer)
return Randomplayer
This is just part of the script.
Instead of doing that, just do. This works, tested it myself.
local Players = game.Players:GetPlayers()
local PlayerToRemove = PlayerINSTANCE --game.Players.PlayerName
table.remove(Players, table.find(Players,PlayerToRemove))
local PlayerToChoose = Players[math.random(1,#Players)] --Only work if there is more than one player.
print(PlayerToChoose)
Also, what’s the error, there doesn’t seem to be an issue with the script.
The error is that Randomplayer ~= Player.Name dosen’t work.
Randomplayer is probably a player, while Player.Name is a string representing the player’s name. Instead, try doing Randomplayer ~= Player