Player.Character

Hey there!

So i’m testing out a function ill need later in my game that changes the player’s character to a character stored in ServerStorage. Unfortunately this doesn’t seem to work… Iv’e already tested out the character itself, which works perfectly fine.

Here is an idea of what i’m trying to do:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(player)
	local Monster = game.ServerStorage.Monster:Clone()
	Monster.Name = player.Name
	
	player.Character = Monster
	
	Monster.Parent = workspace
end)

As you can see its a very simple script, but when i run it i get an error:

image

The script is currently a local script, but iv’e also tried this in a script in ServerScriptService, and got the same error.

Any help would really be appreciated! :+1:

player is not passed to the MouseButton1Click event.

3 Likes

Is there anyway i can perform this function as i want it to?

My bad i got confused for a second and thought you said i can’t use the player variable outside the function in the function realising that the ‘player’ in the brackets was there by mistake.

Thanks for the help anyway! :+1:

1 Like

Oh, my bad. I misread that too.

3 Likes

There seems to be a few issues you might want to look into, shown below:

    1. The client is not able to read anything inside the ServerStorage service.
    1. MouseButton1Click does not have any parameters.
    1. You should check if the player’s character exists, example:
local Character = Player.Character or Player.CharacterAdded:Wait()
-- do fancy charcter stuff here.
1 Like

Thank you! Also do you know how to keep the player alive during the character shifting? The player’s GUI seem to reset when the character is switched.

There is a property called ResetOnSpawn within gui objects. Untick that box.
Even if they die, they will have the gui.

or

Set their humanoid’s health to a higher number / parent a forcefield object to the player’s character.

1 Like