Sorry for explaining bad but, i’ve got a counter for a button which when you click, it gives you a point on the counter, and i would want the points to go on the leaderstat. I don’t know scripting much. So can you help me? The name of the leaderstat is “Clicks”.
Scripts:
Leaderstat:
function playerentered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local Money = Instance.new("IntValue")
Money.Name = "Clicks"
Money.Value = 0
Money.Parent = stats
stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(playerentered)
Script for button:
local buttonstart = script.Parent.ImageButton
local function onButtonActivated ()
local currentvalue = script.Parent.Parent.ScreenGui.Frame.counter.Text
script.Parent.Parent.ScreenGui.Frame.counter.Text = currentvalue + 1
end
buttonstart.Activated:Connect(onButtonActivated)
What you’re gonna wanna do is every time you click the button, fire a remote event to the server through a remote event. In your leaderstats script, add some code that adds the button value by 1 every time the remote event is fired.
This is indeed the solution, and here is how it can be achieved:
Button LocalScript:
local buttonstart = script.Parent.ImageButton
local remote = game.ReplicatedStorage.ChangeValue -- Make a new RemoteEvent and change this value so it leads to it.
function onButtonActivated()
local currentvalue = script.Parent.Parent.ScreenGui.Frame.counter.Text
script.Parent.Parent.ScreenGui.Frame.counter.Text = currentvalue + 1
remote:FireServer() -- Request leaderstats update from the server.
end
buttonstart.Activated:Connect(onButtonActivated)
Add to any ServerScript:
local remote = game.ReplicatedStorage.ChangeValue -- Value should be the same you put in the button LocalScript.
remote.OnServerEvent:Connect(function(plr) -- Update requested.
plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + 1 -- Update value.
end)