Crashes upon joining the game

hello developers, i encountered another problem. when i join my game, it crashes with error 277 (please check your internet connection and try again). but the server still in the game even im on home page. i tried to optimise all the scripts, but it still didnt help. also i see that memory usage in playtest is high (1800 mb). i think it crashes bc i put ball as starter character

local runserv = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local debris = game:GetService("Debris")
local tween = game:GetService("TweenService")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local plr = game.Players.LocalPlayer
local char = script.Parent

local movements = {
	left = false,
	right = false,
	up = false
}

local can_jump = false
local respawning = false
local passing_lvl = false

local debris_count = 5

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}

local mobile_controls = plr.PlayerGui:WaitForChild("MainUI"):WaitForChild("MobileControls")
mobile_controls.Visible = uis.TouchEnabled

----

local function reset_char()
	if char and not respawning then
		respawning = true
		char:WaitForChild("Root").Transparency = 1
		char:WaitForChild("Root").Anchored = true
		char:WaitForChild("Root").CanCollide = false
		char:WaitForChild("Root"):WaitForChild("Move").Velocity = Vector3.new(0,0,0)
		char:WaitForChild("Root").Velocity = Vector3.new(0,0,0)
		script.Sounds.Ouch:Play()
		for i = 1,debris_count do
			local piece = game.ReplicatedStorage.Effects.Debris:Clone()
			piece.Parent = workspace.FX
			piece.Position = char:WaitForChild("Root").Position
			piece.Color = char:WaitForChild("Root").Color
			piece.Velocity = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
			debris:AddItem(piece,game.Players.RespawnTime)
		end
		task.wait(game.Players.RespawnTime)
		for _,obj in pairs(workspace.Levels.Objects:GetChildren()) do
			obj:Destroy()
		end
		for _,obj in pairs(game.ReplicatedStorage.Objects:GetChildren()) do
			local clone = obj:Clone()
			clone.Parent = workspace.Levels.Objects
		end
		char:PivotTo(workspace.Levels["Level_"..plr:WaitForChild("leaderstats"):WaitForChild("Level").Value].Start.CFrame)
		char:WaitForChild("Root").Transparency = 0
		char:WaitForChild("Root").CanCollide = true
		char:WaitForChild("Root").Anchored = false
		respawning = false
	end
end

local function pass_level()
	if char and not respawning and not passing_lvl then
		passing_lvl = true
		char:WaitForChild("Root").Anchored = true
		workspace.Music:Pause()
		script.Sounds.Win:Play()
		char:WaitForChild("Root"):WaitForChild("Move").Velocity = Vector3.new(0,0,0)
		char:WaitForChild("Root").Velocity = Vector3.new(0,0,0)
		task.wait(3)
		char:WaitForChild("Root").Anchored = false
		char:PivotTo(workspace.Levels["Level_"..plr:WaitForChild("leaderstats"):WaitForChild("Level").Value].Start.CFrame)
		workspace.Music:Resume()
		passing_lvl = false
	end
end

----

char:PivotTo(workspace.Levels["Level_"..plr:WaitForChild("leaderstats"):WaitForChild("Level").Value]:WaitForChild("Start").CFrame)

--plr.CharacterAdded:Connect(function(character)
--	char = character
--	char:PivotTo(workspace.Levels["Level_"..plr:WaitForChild("leaderstats"):WaitForChild("Level").Value]:WaitForChild("Start").CFrame)

--	mobile_controls = plr.PlayerGui:WaitForChild("MainUI"):WaitForChild("MobileControls")
--	mobile_controls.Visible = uis.TouchEnabled
	
--	for _,obj in pairs(game.ReplicatedStorage.Objects:GetChildren()) do
--		local clone = obj:Clone()
--		clone.Parent = workspace.Levels.Objects
--	end

--	char:WaitForChild("Root").Touched:Connect(function(hit)
--		if hit:HasTag("KillPart") then
--			reset_char()
--		end
--	end)
	
--	mobile_controls:WaitForChild("Left").MouseButton1Down:Connect(function()
--		movements.left = true
--	end)
--	mobile_controls:WaitForChild("Left").MouseButton1Up:Connect(function()
--		movements.left = false
--	end)

--	mobile_controls:WaitForChild("Right").MouseButton1Down:Connect(function()
--		movements.right = true
--	end)
--	mobile_controls:WaitForChild("Right").MouseButton1Up:Connect(function()
--		movements.right = false
--	end)

--	mobile_controls:WaitForChild("Up").MouseButton1Down:Connect(function()
--		movements.up = true
--	end)
--	mobile_controls:WaitForChild("Up").MouseButton1Up:Connect(function()
--		movements.up = false
--	end)
--end)

uis.InputBegan:Connect(function(key,gameproceed)
	if not gameproceed then
		if key.KeyCode == Enum.KeyCode.D or key.KeyCode == Enum.KeyCode.Right then
			movements.right = true
		elseif key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.Left then
			movements.left = true
		elseif key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.Up then
			movements.up = true
		end
	end
end)

uis.InputEnded:Connect(function(key,gameproceed)
	if not gameproceed then
		if key.KeyCode == Enum.KeyCode.D or key.KeyCode == Enum.KeyCode.Right then
			movements.right = false
		elseif key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.Left then
			movements.left = false
		elseif key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.Up then
			movements.up = false
		end
	end
end)

mobile_controls:WaitForChild("Left").MouseButton1Down:Connect(function()
	movements.left = true
end)
mobile_controls:WaitForChild("Left").MouseButton1Up:Connect(function()
	movements.left = false
end)

mobile_controls:WaitForChild("Right").MouseButton1Down:Connect(function()
	movements.right = true
end)
mobile_controls:WaitForChild("Right").MouseButton1Up:Connect(function()
	movements.right = false
end)

mobile_controls:WaitForChild("Up").MouseButton1Down:Connect(function()
	movements.up = true
end)
mobile_controls:WaitForChild("Up").MouseButton1Up:Connect(function()
	movements.up = false
end)

game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("PassLevel").OnClientEvent:Connect(function(pass)
	if pass == "Next" then
		if not passing_lvl then
			pass_level()
		end
	elseif pass == "Finish" then
		plr.PlayerGui.MainUI.Thanks.Visible = true
	end
end)

char:WaitForChild("Root").Touched:Connect(function(hit)
	if hit:HasTag("KillPart") then
		reset_char()
	end
end)

runserv.Heartbeat:Connect(function()
	if char then
		camera.CFrame = camera.CFrame:Lerp(CFrame.new(char.PrimaryPart.Position - Vector3.new(0,0,20)) * CFrame.Angles(0,math.rad(180),0),0.25)
		
		if not respawning and not passing_lvl then
			if movements.right == true then
				char:WaitForChild("Root"):WaitForChild("Move").Velocity = Vector3.new(-30,0,0)
			elseif movements.left == true then
				char:WaitForChild("Root"):WaitForChild("Move").Velocity = Vector3.new(30,0,0)
			else
				char:WaitForChild("Root"):WaitForChild("Move").Velocity = Vector3.new(0,0,0)
			end

			if movements.up == true and can_jump == true then
				char:WaitForChild("Root"):ApplyImpulse(Vector3.new(0,40,0))
				if script.Sounds.Jump.Playing == false then
					script.Sounds.Jump:Play()
				end
			end

			----
			local raycast1 = workspace:Raycast(char:WaitForChild("Root").Position,Vector3.new(0,-2,0),params)
			if raycast1 then
				if movements.up == false then
					can_jump = true
				end
			else
				can_jump = false
			end
			
			----
			
			if char.PrimaryPart.Position.Y < workspace.FallenPartsDestroyHeight + 200 then
				reset_char()
			end
		end
	end
end)
1 Like

In this case, the error you’re encountering is most likely caused by the game trying to load a ton of stuff all at once; putting stress on your router and forcing a game closure. Are you sure it’s due to this specific script? If so, try and comment some lines out and see if that helps. If it does help, the next step is try and figure out exactly which line is causing the error. If you find it and still need help, just reply to my message with the line and other pieces of relevant code and I’ll see what I can do!

1 Like

even disabling all the scripts and changing character to default, it still crashes.
hm il try to publish the game in other place. sounds silly but mb it will fix

How big is your game? Another question: How many textures/models are in your game? A ton of HTTP requests would also likely cause this error.

there is like 100 parts in workspace. and it doesnt has any textures, only few decals. also forgot to mention, my game isnt big

Any large scripts (1k lines+)? If not then it might just be a problem with your internet. Try and restart your router.

the script i provided here is the largest. i guess its just core scripts problems or internet yeah. thanks for replying

Of course! If you have any other questions, feel free to reply to this message!

i found solution. inner box collision were crashing the game.

while playtesting in studio, usage will be much higher, try testing it in the proper game to see the real usage, for example my games have almost double the usage in studio rather than in the normal game

oh alright, il keep this in mind

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