local badgeId = 242823741 local owner = script.Parent.Parent.Parent.Parent.Owner.Value while wait() do if script.Parent.Parent.Parent.Name == "PurchasedObjects" then if game:GetService("BadgeService"):UserHasBadge(owner.userId, badgeId) then script.Parent.Got.Value = true break end end end
This script works, so nothing needs to be changed, but I was wondering if it was possible to make it more simple and create less lag cause I know while wait() do is not the best way for loops as it does cause a lot of lag. Any ideas?
Well you can use MarketplaceService which has a PlayerOwnsAsset function to tell if the player has the badge however you would still have the problem of HttpCache with it here is a example of how it would be used. And to reduce lag I would suggest wrapping it into a function and creating a check every 10 seconds or connecting it to a event.
local badgeId = 242823741 local owner = script.Parent.Parent.Parent.Parent.Owner.Value local function Check() if script.Parent.Parent.Parent.Name == "PurchasedObjects" then if game:GetService("MarketplaceService"):PlayerOwnsAsset(owner, badgeId) then script.Parent.Got.Value = true return true --tells the while loop the player has the badge end return false --tells the while loop the player doesn't have the badge end while true do if Check() then break end wait(10)--waits 10 seconds till it checks again end
Please up my reputation I hope I have answered correctly for you.
Could do "true" rather than wait()
However remember not to make it a infinite loop. I usually put wait() either on the top of the code or at the bottom so the code has time to have a split second break.
Locked by NinjoOnline, Redbullusa, and yumtaste
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?