LoadCharacter is laggy

Hello, so in my script, player:LoadCharacter() always lags me and sometimes even crashes me how can i fix this?

Server-Sided script

local TeamEvent = game.ReplicatedStorage.RemoteEvent

TeamEvent.OnServerEvent:Connect(function(Player, TeamName)

	if teams:FindFirstChild(TeamName) then
		Player.Team = teams[TeamName]
		task.wait(3)
		Player:LoadCharacter()
		print("Team Changed Successful")
	end
end)

Local Script


local TeamEvent = game.ReplicatedStorage.ChangeTeam

local team1 = script.Parent.MainFrame.Civilian
local team2 = script.Parent.MainFrame["Department of Transportation"]
local team3 = script.Parent.MainFrame["EMS"]
local team5 = script.Parent.MainFrame["Red Town Bay Park Ranger"]
local team6 = script.Parent.MainFrame["Red Town Bay Police"]
local team7 = script.Parent.MainFrame["Red Town Bay Sheriff"]
local team8 = script.Parent.MainFrame["SWAT"]

team1.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team1.Name)
	print("fired")


	if player.Team.Name == "Civilian" then
		-- If already on the civilian team, do nothing
		return
	end
end)

team2.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team2.Name)
	print("fired")


	if player.Team.Name == "Department of Transportation" then
		
		return
	end
end)

team3.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team3.Name)
	print("fired")


	if player.Team.Name == "EMS" then
		
		return
	end
end)

team5.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team5.Name)
	print("fired")


	if player.Team.Name == "Red Town Bay Park Ranger" then
		
		return
	end
end)

team6.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team6.Name)
	print("fired")


	if player.Team.Name == "Red Town Bay Police" then
		 
		return
	end
end)

team7.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team7.Name)
	print("fired")


	if player.Team.Name == "Red Town Bay Sheriff" then
		
		return
	end
end)

team8.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	TeamEvent:FireServer(team8.Name)
	print("fired")


	if player.Team.Name == "SWAT" then
	
		return
	end
end)

your script looks perfectly fine imo, there should be no serious lag caused by loading your character.

its more likely to be caused by another script in the game which runs after your character loads into the game.

look for scripts which use the CharacterAdded, CharacterRemoving or CharacterAppearanceLoaded events and see if they use while true do loops or other unoptimized code.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.