"attempt to index nil with 'Character'"

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to press a ImageButton then ill morph into a character

  2. What is the issue? I Get a "Players.MRzimermann.PlayerGui.Closet.BundleFrame.ImageButton.Script:5: attempt to index nil with ‘Character’ " Error

  3. What solutions have you tried so far? I tried to switch between local and normal script. and i tried to change

local OldPlayer =  player.Character

I Dont figgure out Thy the error come

local DummyButton = script.Parent
local Avatar = game.ReplicatedStorage.Characters 

DummyButton.MouseButton1Click:Connect(function(player)
	local OldCharacter = player.Character
	local NewCharacter = Avatar.Man:Clone()
	
	NewCharacter.HumanoidRootPart.Anchored = false
	NewCharacter.SetPrimaryPart.CFrame(OldCharacter.PrimaryPart.CFrame)
	
	player.Character = NewCharacter
	NewCharacter.Parent = Workspace
	
end)
2 Likes

Is this on a local script or a script?

1 Like

“player” is not a defined parameter, you need to make it so that it is a LocalScript, and give player a value, so you would put

local DummyButton = script.Parent
local Avatar = game.ReplicatedStorage.Characters
local player = game.Players.LocalPlayer

DummyButton.MouseButton1Click:Connect(function()
local OldCharacter = player.Character
local NewCharacter = Avatar.Man:Clone()

NewCharacter.HumanoidRootPart.Anchored = false
NewCharacter.SetPrimaryPart.CFrame(OldCharacter.PrimaryPart.CFrame)

player.Character = NewCharacter
NewCharacter.Parent = Workspace

end)

1 Like

Forgot to format it lol:

local DummyButton = script.Parent
local Avatar = game.ReplicatedStorage.Characters
local player = game.Players.LocalPlayer

DummyButton.MouseButton1Click:Connect(function()
local OldCharacter = player.Character
local NewCharacter = Avatar.Man:Clone()


NewCharacter.HumanoidRootPart.Anchored = false
NewCharacter.SetPrimaryPart.CFrame(OldCharacter.PrimaryPart.CFrame)

player.Character = NewCharacter
NewCharacter.Parent = Workspace


end)

Also I would use workspace instead of Workspace since Workspace is deprecated

this one is a script but the error appared on both of them

Use LocalScript then so that LocalPlayer can be defined, otherwise it won’t work. With using what I provided.

i am pretty much a newbie scripter so when you said and give player a value. do you mean a actuall value or is it in the script?

My fault, I mean to use a variable, like this:

local DummyButton = script.Parent
local Avatar = game.ReplicatedStorage.Characters
local player = game.Players.LocalPlayer --Where player is defined, instead of using a parameter, which only works if it is actually given, like in PlayerAdded or PlayerRemoving events for example, or .OnServerEvent 

DummyButton.MouseButton1Click:Connect(function()
    local OldCharacter = player.Character
    local NewCharacter = Avatar.Man:Clone()
    
    
    NewCharacter.HumanoidRootPart.Anchored = false
    NewCharacter.SetPrimaryPart.CFrame(OldCharacter.PrimaryPart.CFrame)
    
    player.Character = NewCharacter
    NewCharacter.Parent = Workspace
    
    
end)

ok i understand, however i tested and the exact same error appared, i got no clue…

"Players.MRzimermann.PlayerGui.Closet.BundleFrame.ImageButton.LocalScript:5: attempt to index nil with ‘Character’ "

It needs to be in a LocalScript, is it in one?

yes, it is (me waisting some letters to get over 30)

Maybe try:

local OldCharacter = player.Character or player.CharacterAdded:Wait()
1 Like

ooh god my bad at the last one i disabled the script because i was meessing around with both of the. the error do not appare but an other come but i think i can fix it. thanks :smiley:

Which I assume is needing to use :SetPrimaryPartCFrame instead of what you currently have right?

jup i did it thanks agein :smiley: it works as it should

1 Like

Btw I also do suggest you do NewCharacter.Parent = workspace instead of NewCharacter.Parent = Workspace because Workspace is deprecated, but this is just a tip. Good luck with scripting in the future!

1 Like