- What do you want to achieve?
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.
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 other code
Any feedback would be appreciated and ideas to improve this code
That is because clientsided scripts cant run in workspace. You could do a method that uses .Touched instead.
The script itself its not running and its quite odd
Yeah I am going to try and figure out a way to get the player from a server script.
Thank you so much for helping me out!
LocalScripts won’t run inside of
Workspace. Consider moving it to
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 can make use of Attributes, or based on your script, you could do the following:
local Part = workspace:WaitForChild(--Your Path Here)
local cost = Part.Cost.Value -- As an example, you should get the correct path.
Yes, but the thing is i have multiple buttons, each button has a diffrent price and cost. It would be a mess just to type out each button
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
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.