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"
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.
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.