In my script for my sword fighting game, I am trying to give participants points(Cyvicz are the currency) and it give points to the winner but not the participants. the error message is --ServerScriptService.Main:83 : bad argument #2 to '?' (string expected, got Object) . As I said, it is used earlier in the script so I think the method works. I will show only some cause it has nothing to do with the rest. The error is on the 57th line of the inline code. Thanks!
--Setsup participants
participants = {}
for _, player in pairs (game.Players:GetPlayers()) do
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(participants, player)
end
end
--Gets map and teleports
local maps = ss.Maps:GetChildren()
local chosenmap = maps[math.random(1, #maps)]
chosenmap:Clone().Parent = mapHolder
status.Value = "Beginning soon!"
wait(3)
local spawns = chosenmap:FindFirstChild('Spawns'):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
if player and #spawns > 0 then
local torso = player.Character:FindFirstChild('Torso')
local allspawns = math.random(1, #spawns)
local randomspawn = spawns[allspawns]
if randomspawn and torso then
table.remove(spawns, allspawns)
torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 2, 0))
local sword = game.ReplicatedStorage.Sword
local newsword = sword:Clone()
newsword.Parent = player.Backpack
end
end
end
--Round timer
for i = 60, 0, -1 do
if i == 0 then
status.Value = "Time's up!"
break
end
wait(1)--Round end
if #_G.gameplrs == 1 then--*Winner Points
for i, v in pairs (_G.gameplrs) do
if i ~= nil and v ~= nil then
status.Value = v.." is the winner!"
game.Players[v].leaderstats.Cyvicz.Value = game.Players[v].leaderstats.Cyvicz.Value + 50
game.Players[v].leaderstats.XP.Value = game.Players[v].leaderstats.XP.Value + 100
table.remove(participants, i)
break
end
end
break
else
status.Value = i.. " seconds left"
end
end
wait(8)
--Participant Points
if #participants > 0 then
for _, player in pairs (participants) do
game.Players[player].leaderstats.Cyvicz.Value = game.Players[player].leaderstats.Cyvicz.Value + 25
game.Players[player].leaderstats.XP.Value = game.Players[player].leaderstats.XP.Value + 50
game.Players[player].Backpack.Sword.Parent = game.Lighting
for i, v in pairs(_G.gameplrs) do
game.Players[v].Backpack.Sword.Parent = game.Lighting
end
end
end
