Can you tell me whats wrong with line 6?

Hello, its ExoticTwix and im trying to make the player who clicked the GUI button clone. I have made this script but the problem is the output keeps saying Line 6 is a NIL value. Please help me and tell me why this is NIL

It’s because nameofplayer is nil, I’m assuming you want it to be the players character, but the players character loads a few seconds after the player does. Put this line between line 1 and line 2.
player.CharacterAdded:Wait()

Use Player.Character instead of finding a model with their name.

2 Likes

To summarise other replies, here’s what you need to do:

1. Don’t use workspace:FindFirstChild(player.Name)
Instead, use Player.Character, it will always work so long as the Player’s Character exists.

2. Wait for the Player’s Character to exist
Use Player.CharacterAdded:wait() before you find and clone the Player’s Character.

3. Disable the Player’s Character’s Archivable setting before cloning
Not 100% sure if this works, but based on a working ragdoll script that I’ve seen before, they do this first.

2 Likes

Hello, I dont know if i did this right but the way I did it isent working please tell me what im doing wrong since still, that line is nil

Just read the other replies.
(30)

Sorry forgot to add the image here it is

I believe it has to do with a roblox’s character being Archivable = false.

1 Like

You should be doing player.Character or player.CharacterAdded:Wait(), also the player needs to be the player object not a string:

local player = game.players.LocalPlayer
2 Likes

I didn’t notice that lol
(30 chars)

1 Like

Still I cant find what im doing wrong

image

it was just a typo game.Players.LocalPlayer

Basically change the beginning of your script to this:

local player = game.Players.LocalPlayer -- the player
player.CharacterAdded:Wait() -- wait for the character
local nameofplayer = player.Character -- the character
1 Like

The truth is, you cannot modify the character through client and it is definitely because of security on client. For everyone else, it does not have anything to do with the character added. The function is later called after the click event, not after spawning.

Also possibly because of Archivable, as @InedibleGames have previously mentioned.

3 Likes

But the character variable is defined in the beginning, so it does matter.

The Archivable article specifically mentions: Anything instance that has Archivable as false, will be return nil when cloned. Whenever a Player’s Character is placed into workspace. Archivable is always false.

1 Like

Honestly I think Local Scripts dont work for it, now the output is nothing and it looks like this

1 Like

Try this. Probably worth a try.

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local character = LocalPlayer.Character:Clone()
    -- character.Position -- there is no such thing
    character:SetPrimaryPartCFrame(CFrame.new(11, 0.5, 10))
    character.Parent = workspace
end)
1 Like

Maybe make it clone on the server, with a remote event. Or what @Operatik said

@Jaycbee05 @Operatik @InedibleGames @C0lvy123 @GalaxyGourmet This was what I some what wanted to create https://twitter.com/i/status/1236127130175582210

2 Likes