Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I make this more reliable or create less lag? [closed]

Asked by 9 years ago
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?

  • NinjoOnline
0
Is it possible to put this code into an event, e.g. when a player joins the game? this would remove the need for the loop User#5423 17 — 9y
0
What kind of lag are you getting whith this script. In roblox studio go to view->script performance. This will show you the scripts actvity and performance User#5423 17 — 9y

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?

2 answers

Log in to vote
1
Answered by 9 years ago

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.

Ad
Log in to vote
-1
Answered by
Myaxp 3
9 years ago

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.

0
adding a true does nothing.... it just means that i have to put a wait in anyway, with while wait() do end is the exact same as while true do wait() end NinjoOnline 1146 — 9y
0
You could add a variable. EG- o = true then on your code do while o = true do Myaxp 3 — 9y
0
Not all while loops need a wait() depending on the code you make. Myaxp 3 — 9y
0
still gonna add lag NinjoOnline 1146 — 9y
0
All right then. Sorry I guess. Myaxp 3 — 9y