Inside the workspace i got button, i want to detect if the player has enough cash to stand on a button it will tween the size and color.
What is the issue?
The problem is, i can’t seem to make a while loop run in a client side script within workspace, so i don’t know how to get the player,the stats inside the button and all that stuff within a client script without using one in every single script.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve searched everywhere for an answer but i can’t seem to find one.
-Current code
local tweenService = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
while wait(.1) do
local cost = script.Parent.Parent.Cost.Value
local currency = script.Parent.Parent.Currency.Value
if currency == "Cash" then
local stat = plr:FindFirstChild("leaderstats")
local Cash = stat:FindFirstChild("Cash")
if Cash >= cost then
--Run tween
end
else
--run other code
end
end
Any feedback would be appreciated and ideas to improve this code
LocalScripts won’t run inside of Workspace. Consider moving it to StarterPlayerScripts.
Define the Part by using Part:WaitForChild() when loading the script.
Then i would have trouble finding the certain values within the buttons. I want to have a system that is based on that. Thanks anyway for the info, i did not know that
You could use a loop to go through and change each buttons color and size if all the buttons were made the same. it would simplify stuff if you had all the buttons in a folder and then you just looped through the folder or something.
For such cases, you can either loop through each part with an i, v pairs loop, or even better, make use of the CollectionService. Assuming each button has the same structure.
The main button and the fact that they give some points already use CollectionService , but the loop is indeed a very good idea that i forgot about, i will look forward to it. Thank you very much