how to wait for a players character in the code?
You can do this in a local script
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Wait()
Also this one
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Connect(function()
end)
works fr fr? fr? fr? fr? fr? fr?
local Char_One = PLR_ONE.CharacterAdded:Wait()
local Char_Two = PLR_TWO.CharacterAdded:Wait()
--PLAYER LEFT, HOW TO SOLVE???
At that point Char_Num would be nil
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
player:GetPropertyChangedSignal("Parent"):Connect(function()
--player left
end)
Never tried this, but wouldn’t this function just not run since the player leaves before it actually happens?
being away from my country i live in for 3 weeks has kinda screwed me up, huh
Yeah no problem. Also I’m not sure what the poster means by “player left, how to solve” so I’m just throwing out info and guessing what they’re asking.
local characters = {}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
characters[player.Name] = character
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
characters[player.Name] = nil
end)
Wouldn’t the character automatically be set to nil when they leave since the model would be destroyed?
just a backup incase it doesnt get set automatically.
The best way to get the character in my opinion is to do:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Hope this helps!
i just dont actually know how to make my script not crash and stop wortking forever.
What do you mean by “crash and stop working forever”
what if PLR_ONE leaves the game?
while the process?
if PLR_ONE and PLR_TWO then
-- They're still in the game
end
Edit: Reading this again I realize this only works if they leave in the infinitesimally small time between the lines.
I changed the code
Also if you’re doing :Wait() I’m pretty sure it will infinitely delay the rest of the code. I don’t think you have to do this, maybe check if their character exists and if not find a new player to use.