I have this script for after two players have fought. The “winner” is the player that didnt die, and the loser is the player that died. For some reason when this script is ran, it works perfectly for the “winner” but the losers walkspeed is still 16 and they don’t have a forcefield as they can die. I get no error messages, any idea why?
local function disconnectConnections(kills, loserPlayer)
if kills == 5 then
for i, v in ipairs(connections) do
v:Disconnect()
end
if plr1CurrentKills == 5 then
winner = player1
loser = loserPlayer
elseif plr2CurrentKills == 5 then
winner = player2
loser = loserPlayer
end
player1.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
player2.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
winner.leaderstats.Wins.Value += 1
winner.leaderstats.Winstreak.Value += 1
loser.leaderstats.Winstreak.Value = 0
local ff1 = ff:Clone()
local ff2 = ff:Clone()
ff1.Parent = winner.Character
ff2.Parent = loser.Character
ff1.Visible = false
ff2.Visible = false
winner.Character.Humanoid.WalkSpeed = 25
loser.Character.Humanoid.WalkSpeed = 25
local username = loser.Name
local winnerName = winner.Name
local winnerId = winner.UserId
After a players death the player character no longer exists and the old one simply does not respawn but rather is removed. I’d suggest using local character = player.CharacterAdded:Wait()
Which would change the character variable as soon as the player respawns.
Yes, but remove Player.Character as it is basically a one time use only.
Because the Player.Character after destroying would stay nil and not using that rate using CharacterAdded would change it with the new character thus mot breaking the entire code.
This is the updated code and it’s still not working. Theres no error messages in the output.
local function disconnectConnections(kills, loserPlayer)
if kills == 5 then
for i, v in ipairs(connections) do
v:Disconnect()
end
if plr1CurrentKills == 5 then
winner = player1
loser = loserPlayer
elseif plr2CurrentKills == 5 then
winner = player2
loser = loserPlayer
end
player1.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
player2.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
winner.leaderstats.Wins.Value += 1
winner.leaderstats.Winstreak.Value += 1
loser.leaderstats.Winstreak.Value = 0
local ff1 = ff:Clone()
local ff2 = ff:Clone()
local loserChar = loser.CharacterAdded:Wait()
ff1.Parent = winner.Character
ff2.Parent = loserChar
ff1.Visible = false
ff2.Visible = false
winner.Character.Humanoid.WalkSpeed = 25
loserChar.Humanoid.WalkSpeed = 25
local username = loser.Name
local winnerName = winner.Name
local winnerId = winner.UserId
Any ideas how to fix it as it’s still not working?
local function disconnectConnections(kills, loserPlayer)
if kills == 5 then
for i, v in ipairs(connections) do
v:Disconnect()
end
if plr1CurrentKills == 5 then
winner = player1
loser = loserPlayer
elseif plr2CurrentKills == 5 then
winner = player2
loser = loserPlayer
end
player1.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
player2.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
winner.leaderstats.Wins.Value += 1
winner.leaderstats.Winstreak.Value += 1
loser.leaderstats.Winstreak.Value = 0
local ff1 = ff:Clone()
local ff2 = ff:Clone()
local loserChar = loser.CharacterAdded:Wait()
ff1.Parent = winner.Character
ff2.Parent = loserChar
ff1.Visible = false
ff2.Visible = false
winner.Character.Humanoid.WalkSpeed = 25
loserChar.Humanoid.WalkSpeed = 25