I have a second life game pass in my game that allows players to have second chance to beat an obby level if they die.
Sometimes randomly players can spawn too high up from the spawn point (and I have a line of code that sets the HumanoidRootPart CFrame of the player back to spawn). That results in players getting stuck on top of the actual map itself.
Some players have even reported the gamepass breaking entirely, giving players unlimited lives.
playerConnections[player.Name] = player.CharacterAdded:Connect(function(character)
player.CharacterAppearanceLoaded:Wait() -- Make sure that the character is fully loaded
if dataFolder:FindFirstChild("Gamepasses"):FindFirstChild("SecondChance").Value == true then
wait(0.1)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = loadedMap:FindFirstChild("SpawnPart").CFrame
showLastLifeRE:FireClient(player)
wait(0.5)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = player.CharacterAdded:Connect(function(character)
player.CharacterAppearanceLoaded:Wait() -- Make sure that the character is fully loaded
table.remove(players, i)
player.Team = Teams.Lobby
if findMapMusic(loadedMap.Name) ~= nil then
MusicApi.stopMusic(player, findMapMusic(loadedMap.Name))
end
MusicApi.playLobbyMusic(player)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = nil
end)
else
table.remove(players, i)
player.Team = Teams.Lobby
if findMapMusic(loadedMap.Name) ~= nil then
MusicApi.stopMusic(player, findMapMusic(loadedMap.Name))
end
MusicApi.playLobbyMusic(player)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = nil
end
end)
I have tried changing the code many many times, tried using humanoid.Died:Connect(), tried waiting and everything. It always just keeps happening and other members of my team want it to be fixed asap because in their opinion having a glitch like that in game makes the game bad and scares away new players.
playerConnections[player.Name] = player.CharacterAdded:Connect(function(character)
player.CharacterAppearanceLoaded:Wait() -- Make sure that the character is fully loaded
if dataFolder:FindFirstChild("Gamepasses"):FindFirstChild("SecondChance").Value == true then
wait(0.1)
local humanoidRootPart = player.character:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = loadedMap:FindFirstChild("SpawnPart").CFrame
showLastLifeRE:FireClient(player)
wait(0.5)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = player.CharacterAdded:Connect(function(character)
player.CharacterAppearanceLoaded:Wait() -- Make sure that the character is fully loaded
table.remove(players, i)
player.Team = Teams.Lobby
if findMapMusic(loadedMap.Name) ~= nil then
MusicApi.stopMusic(player, findMapMusic(loadedMap.Name))
end
MusicApi.playLobbyMusic(player)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = nil
end)
else
table.remove(players, i)
player.Team = Teams.Lobby
if findMapMusic(loadedMap.Name) ~= nil then
MusicApi.stopMusic(player, findMapMusic(loadedMap.Name))
end
MusicApi.playLobbyMusic(player)
playerConnections[player.Name]:Disconnect()
playerConnections[player.Name] = nil
end
end)