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)
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)
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)
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