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

Ok so i am trying to fix my Coins Leaderstats and i need help?

Soo im trying to make my leaderstat gui work, Its a simple Players > leaderstats > Coins and i tried to do it like this but it no work :(

script.Parent.MouseClick:Connect(function(PlayerWhoClicked)
	local Coins = PlayerWhoClicked.leaderstats.Coins
	Coins.Value = Coins.Value + 1
end)

It is inside Text Button, No Click Detector.. GUI > Frame > Texbutton > "Script"

3 comments

0

Can you provide more info that whether it is a LocalScript or ServerScript, where is your TextButton located, is it really a Textbutton or a ClickDetector?

0

What's the text button for

0

Clicking, Getting Cash?

2 answers

✓ Accepted answer

Hey, malachiRashee!

Since you're using a TextButton, you can't use MouseClick. Looking at the API for a TextButton, we can see that there is no event called MouseClick; instead, it's called MouseButton1Click.

Now that we have the even we need, which is MouseButton1Click, could we change the MouseClick part of your script to MouseButton1Click, then it will be working correctly? We couldn't because we'd be using a LocalScript and have to fire a remote to give the coins. I recommend adding some cooldown on your own time, so people can't spam the event.

Below, you'll find two scripts—one LocalScript, which is to be placed in the TextButton, and one Normal Script, which is to be placed in ServerScriptService. You'll also need to create an event (RemoteEvent) and place it in ReplicatedStorage.

LocalScript:

-- services --
local replicatedstorage = game:GetService("ReplicatedStorage")

-- locals --
local event = replicatedstorage:FindFirstChild("EVENTNAME")

-- script --
script.Parent.MouseButton1Click:Connect(function()
	if event then
		event:FireServer()
	end
end)

Normal Script:

-- services --
local replicatedstorage = game:GetService("ReplicatedStorage")

-- locals --
local event = replicatedstorage:FindFirstChild("EVENTNAME")

-- script
event.OnServerEvent:Connect(function(player)
	if player:FindFirstChild("leaderstats") then
		local leaderstats = player.leaderstats
		
		if leaderstats:FindFirstChild("Coins") then
			leaderstats.Coins += 1
		end
	end
end)

These scripts should work; if they don't, just let me know by replying to my post.

3 comments

0

In your LocalScript, to prevent spam you can add debounce.

0

@ChromeDarkMode How do i add debounce.

0

@ChromeDarkMode not in LocalScript but ServerScript, exploiter can easily modify local code

Text Button does not have such an event called MouseClick, the event for left mouse button is called MouseButton1Click so in your case it would be

script.Parent.MouseButton1Click:Connect(function(PlayerWhoClicked)

Also if the script is Local then the value will ONLY save on the client so if you want other players to see it, use Remote Events.

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