angrybino
(angrybino)
#1
Character Added Event only fires when res-pawning twice. What is causing this, I have to res-pawn my self 2 times until it fires.
--// Services
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
--// Variables
local PlayersInRound = ServerStorage:WaitForChild("PlayersInRound")
--// Events
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats
local inRound = Instance.new("BoolValue")
inRound.Name = "InRound"
inRound.Value = false
inRound.Parent = player.Character
player.CharacterAdded:Connect(function(Character)
inRound.Parent = Character
Character.Humanoid.Died:Connect(function()
print(player.Name.." has died") -- doesnt fire because character added doesnt fire
end)
end)
end)
1 Like
varjoy
(variable)
#2
Yes, you just have to respawn once, then die for it to fires, just edit your code a bit like this:
For some reason CharacterAdded doesn’t fires when player joins game, but do when he respawns
--// Services
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
--// Variables
local PlayersInRound = ServerStorage:WaitForChild("PlayersInRound")
--// Events
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats
local inRound = Instance.new("BoolValue")
inRound.Name = "InRound"
inRound.Value = false
inRound.Parent = player.Character
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = Char:WaitForChild('Humanoid')
hum.Died:Connect(function()
-- stuff here
end)
player.CharacterAdded:Connect(function(Character)
inRound.Parent = Character
Character.Humanoid.Died:Connect(function()
print("esogkyt")
end)
end)
end)
1 Like
angrybino
(angrybino)
#3
It does fire when I join, character added also fires on join as well.
1 Like
varjoy
(variable)
#4
Not for me, at all try my code
1 Like
angrybino
(angrybino)
#5
Your code doesn’t work as well.
1 Like
varjoy
(variable)
#6
I think this might be actually because you’re trying to Parent ‘inRound’ to the Player.Character not cheking if it’s loaded.
Try this:
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
--// Variables
local PlayersInRound = ServerStorage:WaitForChild("PlayersInRound")
--// Events
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local inRound = Instance.new("BoolValue")
inRound.Name = "InRound"
inRound.Value = false
inRound.Parent = char
hum.Died:Connect(function()
-- stuff here
end)
player.CharacterAdded:Connect(function(Character)
inRound.Parent = Character
Character.Humanoid.Died:Connect(function()
print("esogkyt")
end)
end)
end)
Just tested it, and it works
2 Likes
angrybino
(angrybino)
#8
Not really, for some reason humanoid.died event still fires only once…
1 Like
Try this
--// Services
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
--// Variables
local PlayersInRound = ServerStorage:WaitForChild("PlayersInRound")
--// Events
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats
player.CharacterAdded:Connect(function(Character)
local inRound = Instance.new("BoolValue")
inRound.Name = "InRound"
inRound.Value = false
inRound.Parent = Character
Character.Humanoid.Died:Connect(function()
print(player.Name.." has died") -- doesnt fire because character added doesnt fire
end)
end)
end)
You don’t need to use CharacterAdded:Wait(), .CharacterAdded:Connect will be fired in time.
1 Like