So I am trying to script a point system so that when you use a command it will add one point on. I am getting a error and think there is more then one thing wrong so if anyone could help me sort out the error and make sure the script will work that would be great.
local commands = {}
local prefix = "!"
local player = game.Players
local function findPlayer(name)
for i, player in pairs(game.Player:GetPlayers()) do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
commands.test = function(sender, args)
for i,playerName in pairs(args)do
print(playerName)
end
local playertogivepoints = args[1]
if playertogivepoints then
local plrtogive = findPlayer(playertogivepoints)
local points = game.Players.plrtogive.leaderstats.Points
if plrtogive then
points = points + 1
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message,recipient)
message = string.lower(message)
local splitstring = message:split(" ")
local slashcommand = splitstring[1]
local cmd = slashcommand:split(prefix)
local cmdName = cmd[2]
if commands [cmdName] then
local args = {}
for i = 2, #splitstring, 1 do
table.insert(args, splitstring[i])
end
commands[cmdName](player, args)
end
end)
end)