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

Guys I really need help with my CPF Game?

Asked by 9 years ago

Well im creating this CTF Game, and in my game you get 5 min to get the flag and bring it back. But when you don't bring it this is where the problem comes. I get reseted, but the camera is in mid air , but I Can see my self walking down below. It s weird because it dosent happen when I first spawn in my game!! I t only happens when I don't get the flag, and get rested. Help

0
THe code: TortieDowser 0 — 9y
0
It's Roblox's CTF Template SpazzMan502 133 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

We may be able to help if you posted the code.

Ad
Log in to vote
-1
Answered by 9 years ago

The code:


--| WaitForChild |--

-- Waits for parent.child to exist, then returns it local function WaitForChild(parent, childName) assert(parent, "ERROR: WaitForChild: parent is nil") while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end return parent[childName] end


--| Variables |--

local PlayersService = Game:GetService('Players')

local SpawnAllPlayers = WaitForChild(script, 'SpawnAllPlayers') local ClearAllPlayers = WaitForChild(script, 'ClearAllPlayers') local KillAllPlayers = WaitForChild(script, 'KillAllPlayers') local Enable = WaitForChild(script, 'Enable') local Disable = WaitForChild(script, 'Disable')

local RespawnWaveTime = 0 local MinimumRespawnTime = 0 local StartTime = 0

local Enabled = false local DisableSpawnOnJoin = false

local OriginalSetting = nil local NewPlayerConnection = nil local Connections = {}


--| Utility Functions |--

-- Custom logic for Died: wait for next wave, then respawn local function OnDied(player) -- Wait until the next respawn wave local timeUntilNextWave = RespawnWaveTime - ((time() - StartTime) % RespawnWaveTime) if timeUntilNextWave < MinimumRespawnTime then -- The next wave is too soon, wait until the next-next one timeUntilNextWave = timeUntilNextWave + RespawnWaveTime end wait(timeUntilNextWave)

-- Respawn the player if we're still enabled and they're still in the game
if Enabled and player and player.Parent == PlayersService then
    player:LoadCharacter()
end

end

-- Connects OnDied to Humanoid Died, if possible local function ConnectOnDied(player) if player.Character then local humanoid = player.Character:FindFirstChild('Humanoid') if humanoid then humanoid.Died:connect(function() OnDied(player) end) end end end

-- Calls ConnectOnDied once now, and again every time the player spawns. Returns spawn connection local function ConnectPlayer(player) ConnectOnDied(player) return player.CharacterAdded:connect(function() ConnectOnDied(player) end) end

-- Spawns new players (unless disabled), calls ConnectPlayer and saves their connection local function OnPlayerAdded(player) if not DisableSpawnOnJoin then player:LoadCharacter() end Connections[player] = ConnectPlayer(player) end


--| Bindable Functions |--

-- SpawnAllPlayers: Loads all player characters SpawnAllPlayers.OnInvoke = function() for _, player in pairs(PlayersService:GetPlayers()) do player:LoadCharacter() end end

-- ClearAllPlayers: Destroys all player characters ClearAllPlayers.OnInvoke = function() for _, player in pairs(PlayersService:GetPlayers()) do player.Character = nil end end

-- KillAllPlayers: Kills all player characters KillAllPlayers.OnInvoke = function() for _, player in pairs(PlayersService:GetPlayers()) do if player.Character then local humanoid = player.Character:FindFirstChild('Humanoid') if humanoid then humanoid.Health = 0 end end end end

-- Enable: Initializes variables, disables default respawning, and connects to all players Enable.OnInvoke = function(respawnWaveTime, minimumRespawnTime, disableSpawnOnJoin) -- Initialize variables RespawnWaveTime = respawnWaveTime or 5 -- Seconds between each respawn wave MinimumRespawnTime = minimumRespawnTime or 3 -- Players must wait at least this long to respawn DisableSpawnOnJoin = disableSpawnOnJoin or false -- Players will spawn when they join unless this is specified StartTime = time() Enabled = true

-- Disable default respawning but save original setting
OriginalSetting = PlayersService.CharacterAutoLoads
PlayersService.CharacterAutoLoads = false

-- Connect respawning functionality for all players, current and future
NewPlayerConnection = PlayersService.PlayerAdded:connect(OnPlayerAdded)
for _, player in pairs(PlayersService:GetPlayers()) do
    OnPlayerAdded(player)
end

end

-- Disable: Turns off wave spawning and restores setting for default respawning Disable.OnInvoke = function() if Enabled then PlayersService.CharacterAutoLoads = OriginalSetting

    -- Disconnect all saved connections
    NewPlayerConnection:disconnect()
    NewPlayerConnection = nil
    for _, connection in pairs(Connections) do
        connection:disconnect()
    end
    Connections = {}

    Enabled = false
end

end

0
Do not post an answer to reply to someone, it signifies that the Question has been answered. TheeDeathCaster 2368 — 9y

Answer this question