Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click button for plus 1 stats not doing anything?

Asked by 3 years ago

This is the LocalScript inside the frame with the ImageButton to click for stats. It does nothing and displays no errors, HELP???

local buttonstart = script.Parent.ImageButton
local leaderstats = game.Players.LocalPlayer.leaderstats

local function onButtonActivated()
    local currentvalue = leaderstats['Snot Power'].Value == leaderstats['Snot Power'].Value + 1
end

buttonstart.Activated:Connect(onButtonActivated)

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Hello, your problem is that you are trying to change the value on the locally sided instead of server-sided so you are not displaying the points for everyone so that is why you don't get an error because it is technically displaying for the local user but not the server.

You can read more about it here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

For this to work, you need an extra script that gives the points which is relatively easy to do.

STEPS: add a RemoteEvent in ReplicatedStorage and call it AddPoint

LocalScript:

local buttonstart = script.Parent.ImageButton
local RepS = game:GetService("ReplicatedStorage")

local DB = false

local function onButtonActivated()

    if DB == false then

        DB = true
        RepS.AddPoint:FireServer() -- This will launch an event in the server script in ServerScriptService

        wait(1) -- Your Cooldown
        DB = false
    end
end

buttonstart.MouseButton1Click:Connect(onButtonActivated)

Normal Script (In ServerScriptService)

local RepS = game:GetService("ReplicatedStorage")

local function AddPoints(plr)


    local CurrentValue = plr.leaderstats.SnotPower

    CurrentValue.Value = CurrentValue + 1 -- this just sets the SnotPower to the same value and adding 1.
end

RepS.AddPoint.OnServerEvent:Connect(AddPoints) -- When the local script is used// the Imagebutton is pressed it will run our function in line 3

Hopefully It helped!

0
Something I wanted to add is that I see you are using .Activated that is not an instance you should be using you should be using .Mousebutton1Down for GUI's and for ClickDetectors you should use .MouseClick Read more about it here: https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click johnoscarbhv1 137 — 3y
0
Very Cool! Is there a way to make a cooldown so I cant just spam it? Jakob_Cashy 79 — 3y
Ad

Answer this question