Hello, can somebody fix this script for me, when i do /invite playername it show on chatbox player dont exist but he exist, anyway here is the code.
function getPlayerFromNamePart(name)
if name then
for i, player in ipairs(getElementsByType("player")) do
if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then
return player
end
end
end
return false
end
function assignNewTeam ( source, _, playername, teamname )
if not playername then
outputChatBox("Please enter in the player's name that you would like to remove from team!",source,255,0,0)
return
end
local player = getPlayerFromName(playername)
if not player then
player = getPlayerFromNamePart(playername)
end
if not player or isElement(player) then
outputChatBox("Sorry, player doesn't exist!",source,255,0,0)
return
end
local theTeam = getTeamFromName ( teamname )
if not theTeam then
theTeam = createTeam ( teamName )
end
setPlayerTeam ( source, theTeam )
end
addCommandHandler ( "invite", assignNewTeam )
function unassignTeam ( source, _, playername, teamname )
if not playername then
outputChatBox("Please enter in the player's name that you would like to remove from team!",source,255,0,0)
return
end
local player = getPlayerFromName(playername)
if not player then
player = getPlayerFromNamePart(playername)
end
if not player or isElement(player) then
outputChatBox("Sorry, player doesn't exist!",source,255,0,0)
return
end
local theTeam = getPlayerTeam ( player )
if not theTeam then
outputChatBox("Player isn't on a team!",source,255,0,0)
return
end
setPlayerTeam ( player, nil )
end
addCommandHandler ( "dismiss", unassignTeam )