Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Click button for plus 1 stats not doing anything?

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

✓ Accepted answer

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!

2 comments

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

0

Very Cool! Is there a way to make a cooldown so I cant just spam it?

This discussion is preserved as it was. New answers, comments, and votes are closed.