When touching gui it should add plus 1. not working

gui
image
script inside screen gui


local script inside screen gui

In server script service

You should put a localscript under imagebutton and have it fire a RemoteEvent in ReplicatedStorage, for when it has been clicked.

Then, you can add a script in ServerScriptService, have it detect when it has been fired and add + 1, to the leaderstats.

Edit: If it helps, anything done client sided (player), should be in a localscript and anything that is done server sided (server), should be in a script.

In your second script, youā€™re calling WaitForChild on two instances that donā€™t exist within the hierarchy. Thereā€™s no instance called ā€˜OpenButtonā€™ or ā€˜Frameā€™

In your first script, I would make the code wait for the leaderstats, then wait for the Coins Value.

local player = script:FindFirstAncestorOfClass('Player')
local leaderstats = player:WaitForChild('leaderstats')
local Coins = leaderstats:WaitForChild('Coins')

if Coins then
    Coins:GetPropertyChangedSignal('Value'):Connect(function()
        script.Parent.Text = Coins.Value
    end)
end

Also, why is Instance.new('IntValue') giving you a warning?

Script located in ServerScriptService will error, as where you copy pasted the code from used some weird double quotations.
image

Your Script inside the ScreenGui will not run as Scripts only run if they are descendants of workspace or ServerScriptService

Your LocalScript inside the ScreenGui will error as it infinitely yields searching for non-existent children.

The coins script should be a localscript instead of server scripts.

So you can have the:

-- USE LOCALSCRIPTS !
script.Parent.MouseButton1Click:Connect(function()
 script.Parent.Parent.Visible = false -- It's an example
end)
-- It's an example you guys, don't copy that.

Also you did ā€œIntValueā€.

Use NumberValue instead:

game.Players.PlayerAdded:Connect(function(Player)

 local leaderstats = Instance.new("Folder")
 leaderstats.Name = "leaderstats"
 leaderstats.Parent = Player

 local coins = Instance.new("NumberValue", leaderstats)
 coins.Name = "Coins"
 coins.Value = 0
 coins.Parent = leaderstats -- REMOVE THIS ONE, IT'S USELESS !!
end)

For the coins to go up use:

local ls = game.Players:WaitForChild("leaderstats")
script.Parent.MouseButton1Click:Connect(function()
 ls.Coins.Value = ls.Coins.Value + 1
end)

Hope this helps.

1 Like