So for some reason, I have been getting a lot of "Hanging code". And the thing is it says that a variable or service has been hanging which is weird. I don't exactly know why it's hanging so I have came here for help:

This line causes the hanging: local ReplicatedStorage = game:GetService("ReplicatedStorage")

local script in StarterPlayerScripts:

--if game:GetService("RunService"):IsStudio()then return;end
--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Vars \\--
local plr = game.Players.LocalPlayer
local PlayerStats = plr:WaitForChild('PlayerStats')
local PlayerStatus = plr:WaitForChild('PlayerStatus')
local WeaponEquipped = PlayerStatus.WeaponEquipped
local CheckGuildPower = ReplicatedStorage.RemoteFunctions.CheckGuildPower
local Guild_Invitation_Remote = ReplicatedStorage.RemoteEvents.GuildInvitation

local function SetCoreAsync(option, value)
	while not pcall(game.StarterGui.SetCore, game.StarterGui, option, value) do wait() end
end

local function SetCoreGuiEnabledAsync(option, value)
	while not pcall(game.StarterGui.SetCoreGuiEnabled, game.StarterGui, option, value) do wait() end
end

local function PreloadImageAsync(img)
	local imageFrame = Instance.new("ImageLabel")
	imageFrame.Image = img
	game:GetService("ContentProvider"):PreloadAsync({imageFrame})
	imageFrame:Destroy()
end
--// Settings \\--
SetCoreGuiEnabledAsync(Enum.CoreGuiType.All, false)
SetCoreGuiEnabledAsync(Enum.CoreGuiType.Chat, true)

--// Create New Actions \\--
local Invite_To_Guild = 'Invite To Guild'
local Invite_To_Guild_Event = Instance.new("BindableEvent")

local function AvatarContext()
	if WeaponEquipped.Value then
		SetCoreAsync("SetAvatarContextMenuEnabled", false)
	elseif not WeaponEquipped.Value then
		SetCoreAsync("SetAvatarContextMenuEnabled", true)
	end
end

--// This sections will enabled / disable the core gui based on if you got stuff equipped \\--
AvatarContext()

WeaponEquipped.Changed:Connect(AvatarContext)

--// Invite To Guild \\--
local function On_Invite_To_Guild_Event(SelectedPlr) -- This player is the player that was selected
	local IsInGuild,IsOwner,IsCoOwner,GuildName,Members50,GuildImage = CheckGuildPower:InvokeServer()
	if IsInGuild and not Members50 and IsOwner or IsCoOwner then
		Guild_Invitation_Remote:FireServer(SelectedPlr, GuildName, GuildImage)
		print('Sent Invite')	
	else
		print('Player is not in a guild or guild is full or does not have power')
	end
end
 
local Guild_Invitation = { Invite_To_Guild, Invite_To_Guild_Event }
SetCoreAsync("AddAvatarContextMenuOption", Guild_Invitation)
 
Invite_To_Guild_Event.Event:Connect(On_Invite_To_Guild_Event)

Can anyone tell me the cause? How can I fix it?

Thank you for reading.

1 comment

0

The script that caused the game to be hanging is probably not this one. You have to find which script is causing the game to freeze. The reason that this line was shown was because Roblox was currently in the middle of processing that line before the game froze.