Argument 1 Missing or nil

Heya! i’m experiencing an error on line five of this code.

Error: Argument 1 missing or nil

can someone help me resolve this? Thanks!

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("GiveCurrency")

remote.OnServerEvent:Connect(function(plr, CurrencyName, value)
	local currency = plr:WaitForChild("leaderstats"):FindFirstChild(CurrencyName)
	if not currency then
		warn("Attempted arithmetic on an invalid currency when collecting drop.")
		return
	end
	
	currency.Value = currency.Value + value
end)
1 Like

I think thats the wrong code lol

I’m trying to reply all the topics so maybe I wrote the wrong script… Let me check😭

1 Like

It seems like the CurrencyName variable is missing?

1 Like

The currencyname value is inside the drop

Can you show me the script that you use?

1 Like

Here is the server script:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("GiveCurrency")

remote.OnServerEvent:Connect(function(plr, CurrencyName, value)
	local currency = plr:WaitForChild("leaderstats"):FindFirstChild(CurrencyName)
	if not currency then
		warn("Attempted arithmetic on an invalid currency when collecting drop.")
		return
	end
	
	currency.Value = currency.Value + value
end)

Client Script

local player  = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")

while true do
	for i, drop in pairs(workspace.Drops:GetChildren()) do
		if drop:IsA("Part") and drop:FindFirstChild("Value") then
			local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
			if magnitude <= player.Data.MagnetReach.Value then
				local value = drop:WaitForChild("Value").Value
				local CurrencyName = drop:WaitForChild("CurrencyName")
				drop.CanCollide = false
				local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
				tween:Play()
				tween.Completed:Connect(function()
					rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
					drop:Destroy()
					rs:WaitForChild("Sounds").Collect:Play()
				end)
			end
		end
	end
	
	task.wait()
end

Spawner

local DropCurrency = require(game:GetService("ReplicatedStorage"):WaitForChild("Drop"))

local SpawnLocation = game.Workspace:WaitForChild("SpawnPart").CFrame

task.wait(5)

DropCurrency.DropCurrency(SpawnLocation, game.ReplicatedStorage:WaitForChild("Drops").Coin, 10, 5)

Inside a drop part:
image

May I ask what currency name is? Is it a value?

1 Like

CurrencyName in a gem/coin drop is a string value

If it helps: this is the tutorial i’m following

1 Like

So what you are doing wrong is here:

local CurrencyName = drop:WaitForChild("CurrencyName")

See, CurrentName is infact a Value, not a string. Basically, what your suppose to do is:

local CurrencyName = drop:WaitForChild("CurrencyName").Value

Adding a .value gets the data in said CurrencyName. And now testing this it should work.

1 Like

Yep, it works now! Thank you so much :smiley:

Yes. This is the currency script. You can do that OR:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("GiveCurrency")

remote.OnServerEvent:Connect(function(plr, CurrencyName, value)
	local currency = plr:WaitForChild("leaderstats"):FindFirstChild(CurrencyName.Value)
	if not currency then
		warn("Attempted arithmetic on an invalid currency when collecting drop.")
		return
	end
	
	currency.Value = currency.Value + value
end)
1 Like

Excellent! Also I noticed that I asked you quite many questions. Sorry for me being a bit annoying haha. Keep in mind that when making a topic you should provide as much info as you can so others can quickly fix it. Happy scripting. Have a good day : D

1 Like

Its fine, its for my game. So i could sit here for hours trying to fix this lol

Thank you so much :slight_smile:

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