Anyone know whats wrong with this code?

Trying to make a part spawn in a certain position when I click, I already tried to the script and it didn’t work. Anyone know whats wrong?

mouse.Button1Down:connect(function()
	local new = main:clone()
	new.Parent = workspace
	
	new.Anchored = false
	new.CanCollide = true
	new.BrickColor = BrickColor.Random()
	
	new.Position = Vector3.new(-139.5, 6.156, -42.242)
	
end)
1 Like

Are there any errors? The script works fine on my end.

1 Like

the part where it clones just didn’t seem right, Method is a CaseSensitive so clone() should’ve been Clone() instead of that

Being case sensitive means that even if the name has been the same, casing will make it different.

It might be a bug with my studio, but I find that setting the position doesn’t work. Try modifying its CFrame.

new.CFrame = CFrame.new(Vector3.zero) -- example position

In Luau method names are case-sensitive, so :clone() should be :Clone()

mouse.Button1Down:Connect(function()
	local new = main:Clone()
	new.Parent = workspace
	
	new.Anchored = false
	new.CanCollide = true
	new.BrickColor = BrickColor.Random()
	
	new.Position = Vector3.new(-139.5, 6.156, -42.242)
	
end)
1 Like

This is true. Most all method names in Luau are case sensitive, however, :clone() will still work. It is a depreciated method name, but still functions the same. This is the case with other methods as well, such as :connect(). The methods still work and function the same, and are still part of the Luau method library, they just aren’t used/updated.

Back to the issue, I don’t believe that it is an issue with using main:clone() instead of main:Clone(), as I have just tried it and both work just fine.

My hypothesis is that there is an error occurring elsewhere in the code.

EDIT: Possibly with the “main” part variable?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local main = game.Workspace.MainPart -- Replace 'MainPart' with the actual name of the part you want to clone

mouse.Button1Down:connect(function()
	local new = main:Clone()
	new.Parent = workspace
	
	new.Anchored = true
	new.CanCollide = true
	new.BrickColor = BrickColor.Random()
	
	
	local targetPosition = mouse.Hit.p
	new.Position = targetPosition
	
	new:MakeJoints() 
end)

This would position a part relative to where the mouse clicked. I don’t think this is what OP wants, however, if it is then this would work great.

As of now, the only thing we know is that the “script doesn’t work”. We don’t have any other info. :slight_smile:

is this server script or local script?

local script as the mouse inputs

fixed for no reason :confused:

cant believe i forgot to turn off spotify :rage:

and uhh upgraded a bit

1 Like

minecraft be like:(upgraded again)


and for the code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local main = workspace:WaitForChild("main") -- Replace 'MainPart' with the actual name of the part you want to clone

mouse.Button1Down:connect(function()
	local new = main:Clone()
	new.Parent = workspace

	new.Anchored = true
	new.CanCollide = true
	new.BrickColor = BrickColor.Random()


	local targetPosition = mouse.Hit.p + Vector3.new(0,2.5,0)
	new.Position = targetPosition

	new:MakeJoints() 
end)

set your part name that gonna be cloned to main and should work fine.

what is the parent of the script?

hmmm thats true what if script is parented to part?

i’m wondering if it could be parented to the replicated storage, causing it to not run

Set the parent as the last property, this wont fix the script, but it’s just more performant.

mouse.Button1Down:connect(function()
	local new = main:clone()
	
	new.Anchored = false
	new.CanCollide = true
	new.BrickColor = BrickColor.Random()
	
	new.Position = Vector3.new(-139.5, 6.156, -42.242)
	new.Parent = workspace
end)