Why is my coin dropping system now working

CLIENT SIDE: remote:FireServer(ore.PrimaryPart, ReplicatedStorage.Coins.Coins, 12)

SERVER SIDE:
function CoinDrop(origin, coin, amount)

for i=1, amount do
	task.spawn(function()
		local cloneCoin = coin:Clone()

		cloneCoin.CollisionGroup = playerCollisionGroupName

		cloneCoin.Parent = holdingFolder
		cloneCoin.CFrame = origin.CFrame

		cloneCoin.Velocity = Vector3.new(math.random(-20, 20), math.random(55, 70), math.random(-20, 20))


		local attachmentChr = Instance.new("Attachment")
		attachmentChr.Name = "CoinAttachment"
		attachmentChr.Parent = cloneCoin
	end)
end

end

ERROR THAT BRINGS ME: Players.Johnink03.Backpack.TEST.ServerTool:15: invalid ‘for’ limit (number expected, got Instance)

I dont know why it brings me this error if clearly the amount instance is a 12 (a number)

Might try converting it into a number just in case? Sorry if this doesn’t work, but it might be treating as a string or something else.

amount = tonumber(amount)

I already tried that and its not working

When referencing amount, you may be referring to a NumberValue instance. Ensure that amount accesses NumberValue.Value.

no because when I run the function in the same server script without remote event the script works perfectly fine but when I use remote event for some reason that happens

The coin may be getting passed out as the Player. Where you are passing the remote event variables, instead of :Connect(function(parameter,parameter), add a placeholder value before the parameters (for example, :Connect(function(_,parameter,parameter)

1 Like

Check if your paramaters on the server side has the player as the first argument as it’s always the first one when a client fires a remote event to the server

event.OnServerEvent:Connect(function(player,...)
       --Blah
end)

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