Help with clicker button

I’m very new to developing on Roblox and I’m trying to get a button to click and give you 0.1 money every time you click, but it doesn’t work. I know it has to do with number values and stuff like that but I have no idea how to implement a number value into my code. If someone could tell me the problem with my code I would really appreciate it.
Clicker Button:

local player = game.Players.LocalPlayer
local leader = player:WaitForChild("leaderstats")
local money = leader:WaitForChild("Money")

script.Parent.Activated:Connect(function()
	money.Value += 0.1
end)

Display:

local player = game.Players.LocalPlayer
local leader = player:WaitForChild("leaderstats")
local money = leader:WaitForChild("Money")
local gui = script.Parent

gui.MoneyLabel.Text = "Money: " .. money.Value

money.Changed:Connect(function()
	gui.MoneyLabel.Text = "Money: " .. money.Value
end)```
1 Like

I have a few questions.
The Clicker Button script which type of script is it? Local or Script?
Same question goes for the Disaply script.

Also since you are dealing with decimals make sure your value assigned can support that. If it is an IntValue change it to a NumberValue.

The clicker button and display script are both local.

Are there any infinite yields or errors in the output? It could be possible that leaderstats folder isn’t being created under the Player instance.

Also, since both of these are local scripts, you shouldn’t be changing values locally. Instead, you can use remote events. Create a new RemoteEvent inside ReplicatedStorage and name it “ButtonClicked”.

-- your original script but modified a little
local player = game.Players.LocalPlayer
local leader = player:WaitForChild("leaderstats")
local money = leader:WaitForChild("Money")

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.ButtonClicked:FireServer()
end)
-- a Script inside ServerScriptService

local Storage = game.ReplicatedStorage

Storage.ButtonClicked.OnServerEvent:Connect(function(player)
    if player:FindFirstChild('leaderstats') and player.leaderstats:FindFirstChild('Money') then
        player.leaderstats.Money.Value += 0.1
    end
end)

Basically, this script will add 0.1 to the player’s Money value everytime the ButtonClicked remote event is fired.

If the leaderstats folder isn’t being created under the Player instance, then also add this script inside ServerScriptService.

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new('Folder')
    folder.Name = 'leaderstats'
    folder.Parent = player

    local money = Instance.new('NumberValue')
    money.Value = 0
    money.Name = 'Money'
    money.Parent = folder
end)

This script detects when a player joins the server and creates a folder named “leaderstats” and parents it to the player instance, and it also creates a number value called “Money” inside the folder.

The thing you did wrong was changing everything locally. If you don’t understand the Client-Script model, basically every change on server replicates on the client, but client changes doesn’t. But we can replicate client changes to server using RemoteEvents.

Now you can follow the code given by @calvin_coco

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