im making some script, one of then is "if race == X" then change body, but its only for certain races, theres is a lot and i dont do it for almost half of them, so i wanted a way to do a "wait until race is X" i just did if characterAdded and then later "if player.Race == X" then do it, but sometimes my race was this "X" and dont worked, i needed to reset for it work, so i thought in use "wait(3)" or "repeat wait() until plr.Race=="X" ", something like this, but it a good way? wts the better use to it?
another use for it is, each race has some skills and depending on the race i will give those skills so i thought in use this:
repeat wait() until race.Value ~= nil or race.Value ~=""
and then do the "skillX:clone()" in starterpack, wt u guys think, its good?
I think using a coroutine is better. Example:
local thread = coroutine.create(function() -- code end) if race.Value ~= nil or race.Value ~= "" then coroutine.resume(thread) end
Hello, Ariirael!
The way I would do it is by using
repeat race.Changed:Wait() until race.Value ~= nil or race.Value ~=""
That code simply Waits for changes on the value of race
, and does so in a loop.
Therefore, your code isn't using too much CPU time when its just waiting for a change in the race value.
However, if you set the value before starting the script, it could yield until you change it again. You can solve by using a while loop.
Useful links:
If this answers your question, please mark this as the "Accepted Answer"