I have a game where the character instantly gets changed to another rig, and I keep trying to reference Player.Character, and it comes back nil, and I can’t figure out why, and the reason why I can’t simply just have the starter character be the rig I auto change them to is because the game actually uses 2 characters, and rather then just teleporting the character around, it actually changes the character.
so how would I reference the character after it’s been swapped? because I’m completely baffled as to what is going on right now. any help is much appreciated
so how would I reference the character after it’s been swapped? because I’m completely baffled as to what is going on right now. any help is much appreciated
You should be able to access it with Player.Character, you’ll need to define it after you set the player’s character to the rig.
I’m using this to swap, the event is just so I can fire it from the client too.
game.ReplicatedStorage.Events.SwitchCharacters.OnServerEvent:Connect(function(player)
local character = player.Character
if character.Name == "Player1" then
local clone1 = game.Workspace.Player1:Clone()
clone1.Parent = game.Workspace
player.Character = game.Workspace.Player2
elseif character.Name == "Player2" then
local clone2 = game.Workspace.Player2:Clone()
clone2.Parent = game.Workspace
player.Character = game.Workspace.Player1
elseif character.Name ~= "Player1" and character.Name ~= "Player2" then
player.Character = game.Workspace.Player1
end
end)
I could combine my current script and the one that swaps them I guess, and that would then give me the variable, or I could use an object value, which would probably be easier.
I don’t really understanding why you are cloning one character, then trying to parent it the other one.
Also, change the current character name to the player name, so it won’t be picked up by the script again.
Otherwise, every time, players will switch the same character between each other
it gets destroyed, and the players won’t swap between the same ones as its gonna be a single player game. also I knew it would be an issue with multiple people as my play tests are sometimes crashed by my brother messing up the movement
Ah, that explains it.
When you switch characters, do you want the character to replace the current in the same location? Or a different one?
Sometimes, the character just falls of/disappears if isn’t positioned well.
It doesn’t teleport to the original character on default.
see I’m not morphing the character, I’m actually changing it to an entirely deferent rig, and I have it working, but the issue is that I can’t reference the character without it being nil.