So basically I have two teams in my game, the lobby team and the playing team and I want the lobby team to have a RespawnTime of 0.3 seconds, while I want the playing team to have a RespawnTime of 10 seconds, how would I do this?
I have already tried making a local script under StarterPlayerScripts that does a while loop and if the player’s team is the playing team it sets the respawn time to 10, else it sets it to 0.3 seconds. But for some reason this doesn’t work although I see it change the respawn time in the client. Maybe it’s because the RespawnTime can only be change on the server side. But how could I make it different for a certain team?
You’ll have to manually spawn the character in by disabling Players.CharacterAutoLoads (boolean) and check if a player dies via player.CharacterAdded and humanoid.Died then repsawn them using player:LoadCharacter(). While obviously adding in your cooldown before you call this method.
local ChangeRespawnTimeEvent = game.ReplicatedStorage.ChangeRespawnTimeEvent
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Listen for when the player's team changes
character:WaitForChild("Team"):GetPropertyChangedSignal("Value"):Connect(function()
-- Send the team information to the server
ChangeRespawnTimeEvent:FireServer(player.Team.Value)
end)
end)
end)
and then listen to it with a server script
local ChangeRespawnTimeEvent = game.ReplicatedStorage.ChangeRespawnTimeEvent
ChangeRespawnTimeEvent.OnServerEvent:Connect(function(player, team)
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid and team then
if team.Name == "PlayingTeam" then
humanoid.RespawnTime = 10
else
humanoid.RespawnTime = 0.3
end
end
end)
You may need to change some things to fit into your system
local ChangeRespawnTimeEvent = game.ReplicatedStorage.ChangeRespawnTimeEvent
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Listen for when the player's team changes
character:WaitForChild("Team"):GetPropertyChangedSignal("Value"):Connect(function()
-- Send the team information to the server
ChangeRespawnTimeEvent:FireServer(player.Team.Value)
end)
end)
end)
Server script:
local ChangeRespawnTimeEvent = game.ReplicatedStorage.ChangeRespawnTimeEvent
ChangeRespawnTimeEvent.OnServerEvent:Connect(function(player, team)
if team then
if team.Name == "PlayingTeam" then
player.RespawnTime = 10
else
player.RespawnTime = 0.3
end
end
end)