script.Parent.MouseButton1Click:Connect(function(Player)
local plr2 = game:GetService('Players')
local Money = game.Players:WaitForChild("leaderstats"):WaitForChild("Cash")
if plr2 then
local Money = plr2:WaitForChild("leaderstats")
while true do
Money.Value += 5000
end
end
end)
im getting a warning in output and i dont think its running my script even if its not an error but im not good at solving stuff like this. the warning reads
09:32:42.908 Infinite yield possible on ‘Players:WaitForChild(“leaderstats”)’
script.Parent.MouseButton1Click:Connect(function(Player)
local plr2 = game:GetService('Players')
local Money = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
if plr2 then
while true do
Money.Value += 5000
wait(1)
end
end
end)
But im still not getting the leaderstat value after ive clicked my surface gui button. oh i also changed everything to a local script
Local Scripts don’t run in Workspace, you need to use Scripts instead.
script.Parent.MouseButton1Click:Connect(function(Player)
local plr2 = game:GetService('Players')
local Money = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
print("It worked!")
if plr2 then
while true do
Money.Value += 5000
end
end
end)
Are you leaderstats located in a player? You can check it by running the game in studio and going to explorer → Players → player → and there should be leaderstats
Okay, after some investigation I understand that you can’t use player paramater with MouseButton1Click.
I have found an old topic with a solution:
I’m not sure it’s possible to get the player who clicked the button from a server script - at least not easily.
All you need to do is move the SurfaceGui from the Part which it’s currently in (example workspace.Part), put it into your StarterGui and in the Properties of SurfaceGui you will see one called Adornee - Click on this and then click on the part the gui was originally in (workspace.Part) - now you can use local scripts.