Dropper script not working

Hello, I tried making a dropper which drops just one ball if the player has 5 coins but it does not seem to be working

I put the script in the TextButton

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Coins.Value == player.leaderstats.Coins.Value <= 5 then
		local Ball = Instance.new("Part")
		Ball.Size = Vector3.new(1,1,1)
		Ball.Parent = game.Workspace
		Ball.Position = game.Workspace.Dropper.DropZone
	end
end)

This is the dropper model
image
It is giving this error

Is this in a localscript? Regular scripts can’t reference game.Players.LocalPlayer. I will assume “leaderstats” is handled in a regular script, in which case you’d need to set this up using remote events, firing from a localscript to the server in this MouseButton1Click event, then let the server script reference player.leaderstats.Coins.Value.

Your if statement is incorrect, if we assume the player has 2 coins, Roblox lua will translate it as:

2 == 2 <= 5 -->(first comparison runs first)
(2 == 2) <= 5 -->(first condition always true)
true <= 5 -->error because it's impossible to compare a boolean with a number

Instead your condition should be:

--== is exactly 5 coins, < is below, > is above, <= and >= is above/below or equal and ~= is not equal
if player.leaderstats.Coins.Value == 5 then
	--code

tried that but same error and does not make a part

Try this(also it must be a LocalScript for LocalPlayer to work):

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Coins.Value >= 5 then
		local Ball = Instance.new("Part")
		Ball.Size = Vector3.new(1, 1, 1)
		Ball.Parent = workspace
		Ball.Position = workspace.Dropper.DropZone
	end
end)
1 Like

It is actually a normal script

It’s not possible to listen for UI input on the server, or use the LocalPlayer property, you will have to replace your script with a LocalScript and to make the ball creation replicate to the server(and thus other players) you have to communicate with a server script through RemoteEvents.

1 Like

Thanks man It really helped me out as this was for a commission