So let me be honest, there's not really a lot of code here but for most people on scripting helpers anything more than 10 lines of code long is way too much. So as far as scripting helpers is concerned there is a lot of code here.
Let's get this out upfront. All variables are defined. I've made sure the objects that are being used DO exist. I've also made sure that the code is actually running and doing what it should be doing. For instance, I set a value and tell it to print that value just to make sure it set to the correct value. The correct value prints but the what should have happened when that value changed did not.
I should also note, the code is made to work with FE.
When the player first joins the code works fine. If the player dies nothing works again.
It's a bit hacky and not exactly what I want to do but if place the localscript into ReplicatedStorage and clone the script into the character every time it respawns it works fine. It's the only solution I've been able to come up with and I need a better one.
Here is the server script:
local CameraPositions = { -- For camera animation
CFrame.new(-120.710213, 6.15940666, -146.322479, 0.934714735, -0.12219198, 0.333732724, -7.4505806e-009, 0.939036906, 0.3438164, -0.355398953, -0.321370244, 0.877731621),
CFrame.new(-108.146774, 6.46794033, -128.788803, 0.869633198, 0.0542675108, -0.490706801, -0, 0.993940473, 0.109920368, 0.493698418, -0.0955903977, 0.864363611),
CFrame.new(-108.146774, 6.46794033, -128.788803, 0.869633198, 0.0542675108, -0.490706801, -0, 0.993940473, 0.109920368, 0.493698418, -0.0955903977, 0.864363611),
CFrame.new(-74.2134857, 6.53026295, -124.291756, 0.901729107, -0.0609911978, 0.427977532, -3.72528985e-009, 0.989997625, 0.141084835, -0.432301611, -0.127220303, 0.892709613),
CFrame.new(-44.7500305, 6.49922657, -91.4885483, 0.694815218, 0.142276913, -0.704974651, 7.4505806e-009, 0.98023653, 0.197829828, 0.719188392, -0.13745518, 0.681083202),
CFrame.new(17.0646172, 6.57078695, -94.7315521, 0.851611972, -0.122450463, 0.509669423, -0, 0.972331166, 0.233607113, -0.524172664, -0.198942617, 0.828048885),
CFrame.new(74.2607269, 9.99810123, -70.6457367, -0.541897535, -0.221907482, 0.810619652, 7.45058149e-009, 0.964513004, 0.264035791, -0.840444684, 0.143080339, -0.52266711),
CFrame.new(96.2544785, 10.1280718, -22.0046616, -0.248900637, -0.318663836, 0.914604723, 7.45058149e-009, 0.94432354, 0.329018325, -0.968529105, 0.0818928778, -0.235042706),
CFrame.new(93.0390091, 10.137929, 28.5981712, 0.361417294, -0.311375976, 0.878875732, -7.4505806e-009, 0.942590952, 0.333949566, -0.93240422, -0.120695159, 0.340668678),
CFrame.new(54.0205345, 10.1280479, 61.0531998, 0.921771049, -0.127564505, 0.366149694, -0, 0.944330335, 0.328999311, -0.38773489, -0.303262025, 0.870456159),
CFrame.new(10.3288841, 18.4842491, 68.4523773, 0.998818159, 0.0167098902, -0.0456419475, -0, 0.939045846, 0.343792319, 0.0486046076, -0.343386024, 0.937935889),
}
local Joined = {} -- This let's the server know that the player has already joined and not to animate their camera.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local IceCream = ReplicatedStorage.IceCream
local Spawn = workspace:WaitForChild("InitialSpawn")
local SpawnPos = workspace.InitialSpawn.Position
function PlayerSpawned(Player, Character, Torso)
-- Here we handle the spawning of the player.
Torso.Anchored = true
Character:MoveTo(Spawn.Position or SpawnPos or Vector3.new(8, -0.5, 40))
IceCream.PlayerRespawned:FireClient(Player)
end
function PlayerJoined(Player, CamPosTab)
IceCream.PlayerAdded:FireClient(Player, CamPosTab)
end
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
PlayerJoined(Player, CameraPositions)
end)
end)
This is the client script:
--//Player
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Torso = Character:WaitForChild("Torso")
local PlayerGui = Player:WaitForChild("PlayerGui")
local Camera = workspace.CurrentCamera
--//RemoteEvents
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local IceCream = ReplicatedStorage.IceCream
local Events = {}
local Functions = {}
for _, Remote in pairs(IceCream:GetChildren()) do
if Remote:IsA("RemoteEvent") then
table.insert(Events, Remote)
elseif Remote:IsA("RemoteFunction") then
table.insert(Functions, Remote)
else
warn("Found object in IceCream not Remote Object. IceCream should only contain Remote Objects.")
end
end
--//Spawns
local Spawn = workspace:WaitForChild("InitialSpawn")
local SpawnPos = Spawn.Position
--//RunService
local RunService = game:GetService("RunService")
local RenderStepped = RunService.RenderStepped
local Heartbeat = RunService.Heartbeat
local Stepped = RunService.Stepped
--//Menu
local MainMenu = PlayerGui:WaitForChild("MainMenu")
local ButtonFrame = MainMenu:WaitForChild("ButtonFrame")
local Windows = MainMenu:WaitForChild("Windows")
local Play = ButtonFrame:WaitForChild("Play")
local Settings = ButtonFrame:WaitForChild("Settings")
local Blackout = PlayerGui:WaitForChild("Blackout"):WaitForChild("Blackout")
local SkipMain = PlayerGui:WaitForChild("Skip")
local Skip = SkipMain:WaitForChild("TextButton")
--//Booleans
local SkipCam = false
function SetMenuEnabled(Menu, Enabled)
print(Menu.Name..",", Enabled)
Menu.Enabled = Enabled
print(Menu.Enabled)
end
Player.CharacterAdded:connect(function()
MainMenu = PlayerGui.MainMenu
SkipMain = PlayerGui.Skip
end)
Skip.MouseButton1Down:connect(function()
SkipCam = true
end)
function PlayerJoined(CameraPoints)
print("PlayerJoined")
spawn(function()
SetMenuEnabled(SkipMain, true)
SetMenuEnabled(MainMenu, false)
Torso.Anchored = true
Character:MoveTo(Spawn.Position or SpawnPos or Vector3.new(8, -0.5, 40))
Camera.CameraType = Enum.CameraType.Scriptable
end)
Camera.CFrame = CameraPoints[1]
for i = 2, #CameraPoints do
if SkipCam then Camera.CFrame = CameraPoints[#CameraPoints] break end
for j = 0, 1, 0.01 do
RenderStepped:wait()
Camera.CFrame = CameraPoints[i-1]:lerp(CameraPoints[i], j)
if Camera.CFrame == CameraPoints[i] or SkipCam then break end
end
end
SetMenuEnabled(MainMenu, true)
SetMenuEnabled(SkipMain, false)
end
function PlayButtonPressed()
spawn(function()
MainMenu.Enabled = false
for i = 1, 0, -0.05 do
RenderStepped:wait()
Blackout.BackgroundTransparency = i
end
Camera.CameraType = Enum.CameraType.Custom
for i = 0, 1, 0.05 do
RenderStepped:wait()
Blackout.BackgroundTransparency = i
end
Torso.Anchored = false
end)
end
Play.MouseButton1Down:connect(function()
PlayButtonPressed()
end)
--//Connections
for Num, Event in pairs(Events) do
if Event.Name == "PlayerAdded" then
print("Connected, "..Event.Name)
Event.OnClientEvent:connect(PlayerJoined)
end
end

3 comments
Why can't you store the camera CFrames in CFrame values, and just loop through them for the table? It'll cut down on script size
Perhaps it's because they're a part of the joined table already.
At the moment, the joined table is not in use.