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.
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.
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)
I believe it has to do with a roblox’s character being Archivable = false.
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
I didn’t notice that lol
(30 chars)
Still I cant find what im doing wrong
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
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.
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.
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)
@Jaycbee05 @anon81993163 @InedibleGames @C0lvy123 @GalaxyGourmet This was what I some what wanted to create https://twitter.com/i/status/1236127130175582210