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

How to make a server timer for all the players and then teleport two specific people?

Asked by 4 years ago

I'm trying to make a fighting game where a 2 players is teleported after a certain amount of seconds. The teleporting works but the only problem is that the two players that join at different times would have a whole new timer. For example say Player one join the game and starts the time. Ten seconds later Player two joins. Instead of his timer starting at 20 his would restart and start and start and 30. This messes up the whole system and I don't know how to fix it.

Attempts

I've tried many attempts though the one you see in this script works like this. What I tried doing was making a IntVariable inside of replicated storage and set it to 30. Once I did that I told the server keep removing 1 every 1 second until it reached 0 and begun the teleportation. This would make other people cling to that same variable that i made until it has reached 0 on his client too. Though it didn't work. If you can help me that would be very appreciated. Thanks

Local Script

wait(1)
local NumbPlayers = #game.Players:GetPlayers()
local IntGui = script.Parent
local Camera = workspace.CurrentCamera
local NotEP = false
local BattleInt = game.ReplicatedStorage.IntermissionInts.BattleInt.Value
local IntermissionInt = game.ReplicatedStorage.IntermissionInts.InterInt.Value
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local LobbyMusic = game.ReplicatedStorage.Sounds.LobbyMusic:Clone()



LobbyMusic.Parent = PlayerGui
LobbyMusic:Play()



local function IntermissionIntS()
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)
    wait(1)
    IntGui.IntText.Text = (IntermissionInt)

end

local function GameEnd()
    IntGui.IntText.Text = ("Game End in(10)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(9)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(8)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(7)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(6)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(5)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(4)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(3)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(2)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(1)")
    wait(1)
    IntGui.IntText.Text = ("Game End in(0)")
end

if NumbPlayers == 5 then
    IntGui.IntText.Text = "Not Enough Players: Must be more than 1"
end

for i = 1,math.huge do
if NumbPlayers >= 1 then
    game.ReplicatedStorage.Events.TeleEvent2:FireServer()
    IntermissionIntS()
    print("workingss")
        print("nanssik")
    IntGui.IntText.TextColor3 = Color3.new(0,0,0)
local randomPlayer1 = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
local randomPlayer2 = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
if randomPlayer2 == randomPlayer1 then
    randomPlayer2 = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
end


game.ReplicatedStorage.Events.TeleEvent:FireServer(randomPlayer1,randomPlayer2)
    Camera.CameraType = Enum.CameraType.Scriptable
    PlayerGui:FindFirstChild("LobbyMusic"):Destroy()
    local SpectateMusic = game.ReplicatedStorage.Sounds.SpectateMusic:Clone()
    SpectateMusic.Parent = PlayerGui
    SpectateMusic:Play()
for Num = 0,1,.01 do
        print("Lerping")
    Camera.CFrame = Camera.CFrame:lerp(game.Workspace:WaitForChild("CameraPart2").CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
end
wait(2)
for Num = 0,1,.01 do
        print("Lerping2")
    Camera.CFrame = game.Workspace.CameraPart2.CFrame:lerp(game.Workspace:WaitForChild("CameraPart1").CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
end
wait(2)
for Num = 0,1,.01 do
        print("Lerping2")
    Camera.CFrame = game.Workspace.CameraPart1.CFrame:lerp(game.Workspace:WaitForChild("CameraPart").CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
end
wait(0.5)
GameEnd()
PlayerGui:FindFirstChild("SpectateMusic"):Destroy()
local LobbyMusic2 = game.ReplicatedStorage.Sounds.LobbyMusic:Clone()
LobbyMusic2.Parent = PlayerGui
LobbyMusic2:Play()
Camera.CameraType = Enum.CameraType.Custom
wait(5)
end
end

Server Script

local BattleInt = game.ReplicatedStorage.IntermissionInts.BattleInt.Value
local IntermissionInt = game.ReplicatedStorage.IntermissionInts.InterInt.Value





game.ReplicatedStorage.Events.TeleEvent2.OnServerEvent:Connect(function(Player)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    wait(1)
    IntermissionInt = IntermissionInt - 1
    print(IntermissionInt)
    IntermissionInt = 30

end)






game.ReplicatedStorage.Events.TeleEvent.OnServerEvent:Connect(function(Player,randomPlayer1,randomPlayer2)
    print("Sent")

    if Player == randomPlayer1 then
        --Humanoid Stattistics
        local RPC1 = Player.Character
        local RPC1R = RPC1.HumanoidRootPart
        local PlayerGui = randomPlayer1.PlayerGui

        RPC1.Animate.idle.Animation1.AnimationId = "rbxassetid://4291924978"
        RPC1.Animate.idle.Animation2.AnimationId = "rbxassetid://4291924978"
            RPC1.Humanoid.WalkSpeed = 0
        RPC1.Humanoid.JumpPower = 0
        RPC1.Humanoid.AutoRotate = false
        --Gyroing--
            RPC1.Torso.CFrame = game.Workspace.PlayerFace2.CFrame
            local thing = Instance.new("BodyGyro",RPC1.HumanoidRootPart)
        thing.D = 350
        thing.P = 25000
        thing.MaxTorque = Vector3.new(500000,500000,500000)
        spawn(function()
            wait(7)
        print("Done Waiting")
        RPC1.Humanoid.WalkSpeed = 16
        RPC1.Humanoid.JumpPower = 50
        RPC1.Humanoid.AutoRotate = false
        wait(13)
        print("Worked")
        RPC1.Humanoid.AutoRotate = true
        RPC1.Humanoid.Health = RPC1.Humanoid.Health + 1000
        RPC1.Torso.CFrame = game.Workspace.TelePadDone2.CFrame
        thing:Destroy()
        RPC1.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=180435571"
        RPC1.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=180435792"
        end)
        while wait() do
        thing.CFrame = CFrame.new(RPC1R.Position,game.Workspace.PlayerFace2.z.Position)
        end
    end


    if Player == randomPlayer2 then
        --Humanoid Stastics
        local RPC2 = Player.Character
        print(randomPlayer1)
        print(randomPlayer2)
        RPC2.Animate.idle.Animation1.AnimationId = "rbxassetid://4291924978"
        RPC2.Animate.idle.Animation2.AnimationId = "rbxassetid://4291924978"
                local RPC2R = RPC2.HumanoidRootPart
         RPC2.Humanoid.WalkSpeed = 0
        RPC2.Humanoid.JumpPower = 0
        RPC2.Humanoid.AutoRotate = false
        RPC2.Torso.CFrame = game.Workspace.PlayerFace1.CFrame
          -----Gyroing--
            local thing = Instance.new("BodyGyro",RPC2.HumanoidRootPart)
        thing.D = 350
        thing.P = 25000
        thing.MaxTorque = Vector3.new(500000,500000,500000)
        spawn(function()
            wait(7)
        print("Done Waiting")
        RPC2.Humanoid.WalkSpeed = 16
        RPC2.Humanoid.JumpPower = 50
        RPC2.Humanoid.AutoRotate = false
        wait(13)
        print("Worked")
        RPC2.Humanoid.AutoRotate = true
        RPC2.Humanoid.Health = RPC2.Humanoid.Health + 1000
        RPC2.Torso.CFrame = game.Workspace.TelePadDone1.CFrame
        thing:Destroy()
        RPC2.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=180435571"
        RPC2.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=180435792"
        end)


        while wait() do
        thing.CFrame = CFrame.new(RPC2R.Position,game.Workspace.PlayerFace2.z.Position)
        end
    end

    end)

Regards, Bl_ueHistory

Answer this question