Theres still a nil in it
try this :
local player = game.Players.LocalPlayer
local nameofplayer = player.Name
local char = workspace:FindFirstChild(player.Name)
script.Parent.MouseButton1Click:Connect(function()
if char~=nil then
local really = char:Clone()
really.Parent = game.Workspace
really.Position = Vector3.new(11, 0.5, 10)
end
end)
Char would be nil, because you didnât wait for the character.
Still my Variable really is nil
try this
script.Parent.MouseButton1Click:Connect(function()
local character = game.Players.LocalPlayer.Character
if character then
local really = character:Clone()
really.Parent = workspace
really:SetPrimaryPartCFrame(CFrame.new(11, 0.5, 10))
end
end)
The cloned value will always be nil due to the fact that every playerâs character has the property of Archivable set to false.
script.Parent.MouseButton1Click:Connect(function()
local character = game.Players.LocalPlayer.Character
if character then
character.Archivable = true
local really = character:Clone()
really.Parent = workspace
really:SetPrimaryPartCFrame(CFrame.new(11, 0.5, 10))
end
end)
Possibly try that.
try to change game.Players.LocalPlayer to script.Parent.Parent.Parent.Name
A replication of either:
Client-sided only
- LocalScript
- UI calling function to clone your character
- Character duplicates with also LocalScript controls
Server-sided
- LocalScript & Script
- UI firing remotes to clone character
- Character modified to the control scripts for server
local player = game:GetService("Players").LocalPlayer
local char = player.Character
script.Parent.MouseButton1Click:Connect(function()
local really = char:Clone()
really.Parent = workspace
really.Position = Vector3.new(11, .5, 10)
end)
Iâll walk through why your original code wonât work:
- You are trying to get the player but instead referencing the name, this just wonât work.
- When you clone the player in your event, you are trying to clone a string. The :Clone() method only works on instances, not strings.
Apart from that everything looks fine.
Also I have a question, is there a way to make the position where a part is located. Like if that part moves it still gets the position and clone there?
I think youâre looking for something that has to do with relative positions. However, it is more suitable if you created another topic as discussing this will derail it from the current topic.
Archivable is also a problem with the original code. Instances with Archivable on will return nil when the Clone method is used with them.