REPOSTED BECAUSE DIDNT GET ANSWER SORRY
this is the regular script inside a textbutton in a frame in a screengui
no errors
local Part = script.Parent Part.MouseButton1Click:Connect(function() local player = script.Parent.Parent.Parent.Parent.Parent if player then local leaderstats = player:WaitForChild("leaderstats") local Currency = leaderstats.Rebirths local Selling = leaderstats.Coins if (Selling.Value >= 1500) then Currency.Value = Currency.Value + Selling.Value + 1 Selling.Value = 0 player.leaderstats.Changes.Value = 0 game.Workspace.clink.Playing = true wait(2) game.Workspace.clink.Playing = false end end end)
Idk how to get the sound "clink" to just play for the local player, because it would not play when inside the scripts Parent.
its also converting all coins to rebirths and adding 1, how fix?
ok so uh, heres the thing
do not use normal scripts for guis. It is a bad practice. use local scripts instead since guis are locally designated as well.
to change stats, you will need a remote event.
how to fix this:
1.add a folder in replicatedstorage, (lets just name it GameRemotes) and then a RemoteFunction inside it called Rebirth.
2.put this script in the same place you placed your script, and make sure it is a local script.
local button = script.Parent local rs = game:GetService("ReplicatedStorage") local clink = game.Workspace:WaitForChild("clink") button.MouseButton1Click:Connect(function() local player = game:GetService("Players").LocalPlayer rs:WaitForChild("GameRemotes"):WaitForChild("Rebirth"):InvokeServer() -- from here on, the script will wait until a server script i will place is done doing its thing then continue, this is to prevent a "sound plays before stats change" bug clink.Playing = true wait(2) clink.Playing = false end)
3.add a normal script in serverscriptservice with the following code:
local Rebirth = game:GetService("ReplicatedStorage"):FindFirstChild("GameRemotes"):FindFirstChild("Rebirth") Rebirth.OnServerInvoke:Connect(function(player) local lstats = player:FindFirstChild("leaderstats") local rebirths = lstats:FindFirstChild("Rebirths") local coins = lstats:FindFirstChild("Coins") if coins.Value < 1500 then return end rebirths.Value += 1 -- rebirths.Value = rebirths.Value + 1 but shorter coins.Value = 0 lstats:FindFirstChild("Changes").Value = 0 end)
some links for further explanation: