Argument 1 missing or nil

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)

Line that’s giving an error:

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

Datastore Script:

local Data = game:GetService("DataStoreService"):GetDataStore("Currencies")

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder", game.ServerStorage.ds)
	Folder.Name = plr.Name
	local Folder2 = Instance.new("Folder", game.ReplicatedStorage.ds)
	Folder2.Name = plr.Name
	local Folder3 = Instance.new("Folder", plr)
	Folder3.Name = "leaderstats"
	local money = Instance.new("NumberValue", Folder2)
	money.Name = "Money"
	local wins = Instance.new("NumberValue", Folder3)
	wins.Name = "Wins"
	local multiplier = Instance.new("NumberValue", Folder2)
	multiplier.Name = "multiplier"
	local hasBloody = Instance.new("NumberValue", Folder)
	hasBloody.Name = "Bloody Knife"
	local hasPencil = Instance.new("NumberValue", Folder)
	hasPencil.Name = "Pencil Knife"
	local hasRainbow = Instance.new("NumberValue", Folder)
	hasRainbow.Name = "Rainbow Knife"
	local hasNoob = Instance.new("NumberValue", Folder)
	hasNoob.Name = "Noob Knife"

	local saveditems = Data:GetAsync(plr.userId)

	if saveditems then
		money.Value = saveditems.Money
		wins.Value = saveditems.Wins
		hasBloody.Value = saveditems.hasBloody
		hasPencil.Value = saveditems.hasPencil
		hasRainbow.Value = saveditems.hasRainbow
		hasNoob.Value = saveditems.hasNoob
		multiplier.Value = 1
	else

		money.Value = 0 
		wins.Value = 0
		hasBloody.Value = 0
		hasPencil.Value = 0
		hasRainbow.Value = 0
		hasNoob.Value = 0
		multiplier.Value = 1
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local Saving = 
		{
			["Money"] = game.ReplicatedStorage.ds:FindFirstChild(plr.Name).Money.Value;
			["Wins"] = game.Players:FindFirstChild(plr.Name).Wins.Value;
			["hasNoob"] = game.ServerStorage.ds:FindFirstChild(plr.Name):FindFirstChild("Noob Knife").Value;
			["hasPencil"] = game.ServerStorage.ds:FindFirstChild(plr.Name):FindFirstChild("Pencil Knife").Value;
			["hasRainbow"] = game.ServerStorage.ds:FindFirstChild(plr.Name):FindFirstChild("Rainbow Knife").Value;
			["hasBloody"] = game.ServerStorage.ds:FindFirstChild(plr.Name):FindFirstChild("Bloody Knife").Value;
			["multiplier"] = game.ReplicatedStorage.ds:FindFirstChild(plr.Name).multiplier.Value;
		}

	Data:SetAsync(plr.userId, Saving)
end)

The line that’s giving you issues isn’t even in the full script?

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.

ah alright ill do the full script then.

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 is a Weird DataStore, its all messy, everywhere, and some code is just completely unnecessary

1 Like

yeah, i know. datastores arent my strong side

anyways lets not get offtrack and focus on the title

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
1 Like

oh yeah, thanks for reminding me also yes i agree it is cleaner

now its giving me this error


line 158 is

local Multiplier = game.ReplicatedStorage.ds[player.Name].multiplier

fixed it, just had to remove .Name

I think I have a solution to this tbh

1 Like

already fixed it, no need but thanks anyways

Mark it as solved then. Simple

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.