Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this script only run on player join?

Asked by 8 years ago

I need this cut scene script to only run on player join, but it currently also runs on respawn....

All parts/code is valid and working except for the stated reason

player = script.Parent.Parent
char = player.Character
cam = game.Workspace.CurrentCamera  
char.Humanoid.WalkSpeed = 0
game.Workspace.CurrentCamera.CameraType = "Scriptable"
wait()

local Players = game:GetService("Players")

game.Workspace.CurrentCamera.CameraType = "Track"

intro = game.Workspace.Intro
pos1 = intro.IntroCam1
pos2 = intro.pos2
pos3 = intro.Pos3
pos4 = intro.Pos4
pos5 = intro.Pos5
pos6 = intro.Pos6
pos7 = intro.Pos7
endpos = intro.EndPos

function onPlayerAdded()
    game.Workspace.CurrentCamera.CameraType = "Scriptable"
    char.Humanoid.WalkSpeed = 0
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos1.Position),CFrame.new(pos1.Rotation),2)
    wait(2)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos2.Position),CFrame.new(pos2.Rotation),3)
    wait(3)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos3.Position),CFrame.new(pos3.Rotation),1)
    wait(1)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos4.Position),CFrame.new(pos4.Rotation),5)
    wait(5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos5.Position),CFrame.new(pos5.Rotation),3)
    wait(3)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos6.Position),CFrame.new(pos6.Rotation*90),5)
    wait(5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos7.Position),CFrame.new(pos7.Rotation),3.5)
    wait(3.5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos7.Position),CFrame.new(pos7.Rotation),1.5)
    wait()
    char.Humanoid.WalkSpeed = 16
    game.Workspace.CurrentCamera.CameraType = "Track"
end

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded()
end
0
connect your function duckyo01 120 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Connect a function to OnPlayerAdded. This makes it run when a player joins.

player = script.Parent.Parent
char = player.Character
cam = game.Workspace.CurrentCamera  
char.Humanoid.WalkSpeed = 0
game.Workspace.CurrentCamera.CameraType = "Scriptable"
wait()

local Players = game:GetService("Players")

game.Workspace.CurrentCamera.CameraType = "Track"

intro = game.Workspace.Intro
pos1 = intro.IntroCam1
pos2 = intro.pos2
pos3 = intro.Pos3
pos4 = intro.Pos4
pos5 = intro.Pos5
pos6 = intro.Pos6
pos7 = intro.Pos7
endpos = intro.EndPos

function onPlayerAdded()
    game.Workspace.CurrentCamera.CameraType = "Scriptable"
    char.Humanoid.WalkSpeed = 0
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos1.Position),CFrame.new(pos1.Rotation),2)
    wait(2)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos2.Position),CFrame.new(pos2.Rotation),3)
    wait(3)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos3.Position),CFrame.new(pos3.Rotation),1)
    wait(1)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos4.Position),CFrame.new(pos4.Rotation),5)
    wait(5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos5.Position),CFrame.new(pos5.Rotation),3)
    wait(3)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos6.Position),CFrame.new(pos6.Rotation*90),5)
    wait(5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos7.Position),CFrame.new(pos7.Rotation),3.5)
    wait(3.5)
    game.Workspace.CurrentCamera:Interpolate(CFrame.new(pos7.Position),CFrame.new(pos7.Rotation),1.5)
    wait()
    char.Humanoid.WalkSpeed = 16
    game.Workspace.CurrentCamera.CameraType = "Track"
end

game.Players.PlayerAdded:connect(OnPlayerAdded)

Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

You have it running for each and every player at once. Instead, connect the function!

At the bottom, put this:

game.Players.PlayerAdded:connect(onPlayerAdded)
0
When I run it now, nothing happens... I dont see an error (but I have a lot of errors from a script I cant edit due to not mine (groups)) mat123321g 25 — 8y

Answer this question