computer-sciencegame-enginestartuprobloxsolution

How do i make a roblox script start as soon as a player joins the game?


local Theme = workspace.CrucibleMusic1
local FlashEffect = script.Parent.FlashEffect
local Camera = workspace.Camera
local ScreenZoomAmount = 0.025 -- How much screen zoom when music is playing
local FlashAmount = 0.75 -- How much screen flash when music is playing
local ScreenAngelsAmount = 0.003 -- How much screen angles change when music is playing
local StandardFieldOfView = 70 -- Standard FieldOfView on roblox better set it to 70

game:GetService("RunService").RenderStepped:Connect(function()
    Camera.FieldOfView = StandardFieldOfView - Theme.PlaybackLoudness * ScreenZoomAmount
    FlashEffect.BackgroundTransparency = 1 - Theme.PlaybackLoudness * FlashAmount
    Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(0, 
        0, math.rad(math.random(- Theme.PlaybackLoudness,
            Theme.PlaybackLoudness) * ScreenAngelsAmount)) + Vector3.new(
        math.rad(math.random( - Theme.PlaybackLoudness * ScreenAngelsAmount,
            Theme.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
        math.rad(math.random( - Theme.PlaybackLoudness * ScreenAngelsAmount,
            Theme.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
        math.rad(math.random( - Theme.PlaybackLoudness * ScreenAngelsAmount,
            Theme.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount )
    )     
end)

How do i make this instantly start when i join? Im trying to figure out how to make this instantly start when a player joins the game, But i cant figure out how to do that. I tried putting it in ServerScriptService but it wouldnt run, Any ideas?


Solution

  • If the code is put in StarterPlayerScripts or something similar, the script is replicated and is already running on startup. ServerScriptService is for server scripts. They run on the server, not the client.