✓ 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:
local replicatedstorage = game:GetService("ReplicatedStorage")
local event = replicatedstorage:FindFirstChild("EVENTNAME")
script.Parent.MouseButton1Click:Connect(function()
if event then
event:FireServer()
end
end)
Normal Script:
local replicatedstorage = game:GetService("ReplicatedStorage")
local event = replicatedstorage:FindFirstChild("EVENTNAME")
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
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?
What's the text button for
Clicking, Getting Cash?