I have this code, and it checks if the person has already unlocked the color. If it's not unlocked, it will work, but if it's already unlocked it will freeze the computer. Any ideas as to why?
I'm also streaming if you guys want to see the context around it. I can also explain it with my voice there.
local color = script.Parent.BackgroundColor3 local brickcolor = BrickColor.new(color) local brickcolorname = brickcolor.Name local backpack = game.Players.LocalPlayer.Backpack.Player.ColorValues.ChatColor local gamepassreq = script.Parent.Parent.Gamepass local player = game.Players.LocalPlayer local passcoderequire = script.Parent.Parent.Parent.Parent.Parent.PasscodeRequire codestable = _G.codes unlockedcolors = _G.unlockedcolors script.Parent.BackgroundColor3 = Color3.new(color.r, color.g, color.b) function isAuthenticated(player) return game:GetService('GamePassService'):PlayerHasPass(player, gamepassreq) end script.Parent.MouseButton1Down:connect(function() print(brickcolorname) if script.Parent.Parent.ColorName.Text == 'Twitter Color Pack' or script.Parent.Parent.ColorName.Text == 'Twitch Color Pack' then for i = 1, #codestable do if tostring(brickcolor) == codestable[i][1] then for f = 1, #unlockedcolors do wait() print('Unlocked colors: ' .. unlockedcolors[f]) print('CodesTable ' .. codestable[i][1] .. ' ' .. i) print(unlockedcolors[f] == codestable[i][1]) if unlockedcolors[f] == codestable[i][1] then print('Through') changething() else passcoderequire.Position = UDim2.new(.5, 0, .5 ,0) passcoderequire.Size = UDim2.new(0, 0, 0 ,0) passcoderequire.Visible = true passcoderequire:TweenSizeAndPosition(UDim2.new(.2, 0, .2, 0), UDim2.new(.4, 0, .4, 0), 'Out', 'Linear', .25) passcoderequire.OK.MouseButton1Down:connect(function() if passcoderequire.A.Text == codestable[i][2] then a = require(game.Players.LocalPlayer.PlayerGui.StartGui.FirstFrame.AwardScript) a(player.Name, brickcolorname) passcoderequire.Position = UDim2.new(.4, 0, .4 ,0) passcoderequire.Size = UDim2.new(0.2, 0, 0.2 ,0) passcoderequire:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(.5, 0, .5, 0), 'Out', 'Linear', .25) repeat wait() until passcoderequire.Size.X.Scale <= .05 passcoderequire.Visible = false changething() passcoderequire.A.Text = 'Enter code here' else passcoderequire.Incorrect.Visible = true wait(1) passcoderequire.Incorrect.Visible = false end end) end end end end else if isAuthenticated{player} then--checks gamepass backpack.Value = brickcolor script.Parent.Text = 'X' end end end) game.Players.LocalPlayer.Backpack.Player.ColorValues.ChatColor.Changed:connect(function() changething() end) function changething() backpack.Value = brickcolor script.Parent.Text = 'X' end
You react to any changes to ChatColor
(aka backpack
-- you should probably clean that up on line 70 to just be backpack.Changed:connect
) by the function changething
.
However, you also change backpack
in that function which causes the event to be called again -- which repeats the process (causing the hang)
changething
should ensure that the values actually needs changing before changing it, to prevent this (will call it twice still, but that's okay, for this script at least)
function changething() if backpack.Value ~= brickcolor then backpack.Value = brickcolor script.Parent.Text = 'X' end end