So basically im trying to make a script that awards money on win but its saying “Argument 1 missing or nil” and i tried fixing it but no luck (srry if its hard to read)
it is, i just didnt include it cause its not necessary but heres the full for loop
for i, player in pairs(playing) do -- Loop through all winners
game.Players:FindFirstChild(player).leaderstats.Wins.Value = game.Players:FindFirstChild(player).leaderstats.Wins.Value + 1
game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value = game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value + 10 * game.ReplicatedStorage.ds:FindFirstChild(player.Name).multiplier.Value
end
Include the full script, I need to know how the playing table is created. Since all of your data values are stored as game objects there is a lot of points of failure based off how you approach things.
local playing = {}
local inRound = game.ReplicatedStorage.InRound
function scriptfunnyhaha()
local intermission = 10
local roundLength = 180
local status = game.ReplicatedStorage.Status
local playingTeam = game.Teams.Playing
local playersingame = 0
local murdingamechecked = {}
local lobbyTeam = game.Teams.Lobby
local murdermodule = require(game.ReplicatedStorage.MurderModule)
inRound.Changed:Connect(function()
if inRound.Value == true then
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
local humanRoot = char:WaitForChild("HumanoidRootPart")
plr.Team = playingTeam
char:WaitForChild("Humanoid").Died:Connect(function(playerwhodied)
plr.Team = lobbyTeam
end)
end
else
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
if char:FindFirstChild("HumanoidRootPart") then
local humanRoot = char:WaitForChild("HumanoidRootPart")
local human = char.Humanoid
plr.Team = lobbyTeam
human:UnequipTools()
for i, tool in pairs(plr.Backpack:GetChildren()) do
if tool.Name == "6 gold chain guns" then
else
tool:Destroy()
end
end
end
end
end
end)
local function round()
while true do
local requiredPlayers = 2
repeat
wait(1)
status.Value = "Atleast ".. requiredPlayers.." players are needed to start a round"
until #game.Players:GetChildren() >= requiredPlayers
inRound.Value = false
table.clear(playing)
for i = intermission, 0, -1 do
status.Value = "Game will start in "..i.." seconds"
wait(1)
end
inRound.Value = true
for i, plr in pairs(game.Players:GetChildren()) do
if plr.Team.Name == "Playing" then
local rep = game:GetService("ReplicatedStorage")
local ds = rep.destroyspectate
ds:FireClient(plr)
plr.PlayerGui.Spectate:Destroy()
game.ReplicatedStorage.ds:FindFirstChild(plr.Name).multiplier.Value = 1
table.insert(playing, plr.Name)
end
end
playersingame = #game.Players:GetPlayers()
murdermodule.ChooseRoles()
for i = roundLength, 0, -1 do
status.Value = "Game will end in "..i.." seconds"
local murdereralive = false
local nonmurderersalive = false
local murderer
print(table.concat(playing))
for v, playerInRound in pairs(playing) do
if game.Players:FindFirstChild(playerInRound) then
if game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value == "Murderer" then
murdereralive = true
murderer = game.Players:FindFirstChild(playerInRound)
elseif game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value ~= "Murderer" then
nonmurderersalive = true
end
else
if murderer == playerInRound then
status.Value = "The Murderer has turned themselves in."
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
end
end
wait(3)
return scriptfunnyhaha()
end
end
end
if #playing == 0 then
status.Value = "Everyone Has Died"
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
end
end
wait(3)
return scriptfunnyhaha()
end
if murdereralive == true and nonmurderersalive == false then
status.Value = "The Murderer got away with their crimes."
for i, player in pairs(playing) do -- Loop through all winners
-- Your stats code
game.Players:FindFirstChild(player).leaderstats.Wins.Value = game.Players:FindFirstChild(player).leaderstats.Wins.Value + 1
game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value = game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value + 10 * game.ReplicatedStorage.ds:FindFirstChild(player.Name).multiplier.Value
end
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
end
end
wait(3)
return scriptfunnyhaha()
end
if murdereralive == false and nonmurderersalive == true then
status.Value = "The Murderer has been rightfully killed!"
for i, player in pairs(playing) do -- Loop through all winners
-- Your stats code
game.Players:FindFirstChild(player).leaderstats.Wins.Value = game.Players:FindFirstChild(player).leaderstats.Wins.Value + 1
game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value = game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value + 10 * game.ReplicatedStorage.ds:FindFirstChild(player.Name).multiplier.Value
end
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
end
end
wait(3)
return scriptfunnyhaha()
end
if nonmurderersalive == true and i == 0 then
status.Value = "The Murderer took too long and got caught."
for i, player in pairs(playing) do -- Loop through all winners
if player.Name ~= murderer then
game.Players:FindFirstChild(player).leaderstats.Wins.Value = game.Players:FindFirstChild(player).leaderstats.Wins.Value + 1
game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value = game.ReplicatedStorage.ds:FindFirstChild(player.Name).Money.Value + 10 * game.ReplicatedStorage.ds:FindFirstChild(player.Name).multiplier.Value
end
-- Your stats code
end
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
if game.Workspace:FindFirstChild("GunClone") then
game.Workspace.GunClone:Destroy()
end
end
wait(3)
return scriptfunnyhaha()
end
wait(1)
end
wait(3)
end
end
spawn(round)
end
scriptfunnyhaha()
local function onplayerdied(player)
local findd = table.find(playing, player.Name)
table.remove(playing, findd)
end
game:GetService("ReplicatedStorage").OnDied.OnServerEvent:Connect(onplayerdied)
This should be a more Simplified version your code:
Instead of doing Var = Var + Num, you can do Var += Num, Both work the same, and lets be real, += is cleaner
And instead of doing Ex:FindFirstChild(plr.Name), you can do Ex[plr.Name]
for i, player in pairs(playing) do -- Loop through all winners
local Multiplier = game.ReplicatedStorage.ds[player.Name].multiplier
player.leaderstats.Wins.Value += 1
game.ReplicatedStorage.ds[player.Name].Money.Value += 10 * Multiplier.Value
end