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)