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

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

Asked by 4 years ago
Edited 4 years ago

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"

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? BestCreativeBoy 1395 — 4y
0
What's the text button for MarcTheRubixQb 153 — 4y
0
Clicking, Getting Cash? malachiRashee 24 — 4y

2 answers

Log in to vote
1
Answered by
NotedAPI 810 Moderation Voter
4 years ago

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.

0
In your LocalScript, to prevent spam you can add debounce. ChromeDarkMode 15 — 4y
0
@ChromeDarkMode How do i add debounce. malachiRashee 24 — 4y
0
@ChromeDarkMode not in LocalScript but ServerScript, exploiter can easily modify local code imKirda 4491 — 4y
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

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.

Answer this question