Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why would this script cause my game to freeze but no one else's?

Okay so to elaborate, me and my friend a long time ago started making a game, and me and him wanted a team that only he and I could access, so I implemented the following script. However, it would always freeze my game, but no one else's, including "Sinx_Clair" as he could load into the game and play it without any problems occurring. But I also realized if I played on some other account aka my alt, "thesavagery214", it would work perfectly fine, without freezing me. It wasn't until I was making a new team change menu today, that I realized this script is what would make my main account freeze. However, I see nothing that in theory would freeze my main account but not my alt or my friends.

((This is a local script in a GUI Button))

local plr = game.Players.LocalPlayer

while true do
	if plr.Name == "thesavagery212" then
		script.Parent.Visible = true
	else
		script.Parent:Destroy()
	end
end

while true do
	if plr.Name == "Sinx_Clair" then
		script.Parent.Visible = true
	else
		script.Parent:Destroy()
	end
end

while true do
	if plr.Name == "thesavagery214" then
		script.Parent.Visible = true
	else
		script.Parent:Destroy()
	end
end

1 comment

0

you are doing while true do. and no wait() statement at the end. if you do that, you will make your game lag like crazy

3 answers

You did a loop without a wait which causes your game to freeze. Also, script doesn't continue past the first loop unless you do a coroutine or something bc the loop never ends so the script cant move on to the next part. you could also do elseif plr.name == 'Sinx_Clair' then

This should be an easy fix and i've made it more organized

(You need to put a cooldown on the loops)

local plr = game.Players.LocalPlayer

while wait() do
    if plr.Name == "thesavagery212" or plr.Name == "Sinx_Clair" or plr.Name == "thesavagery214" then
        script.Parent.Visible = true
    else
        script.Parent:Destroy()
    end
end

(Follow up to BulletProofVast's answer) you seem to be trying to check the player's name too. That doesn't require an infinite loop, you can just do this:

local Admins = {
	"thesavagery212", -- list of admin names (i suggest userids tho)
	"Sinx_Clair",
	"thesavagery214",
}

local plr = game:GetService("Players").LocalPlayer

for i,v in ipairs(Admins) do -- search everything in the table
	if plr.Name == v then -- i can just do table.find(table, (what i wanna find)) but this method is quicker (at least, according to Evercyan lmao)
		script.Parent.Visible = true
	else
		script.Parent:Destroy()
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.