Code doesnt working

I want to do that when player clicks part then other part in workspace clones.
theres script:

local cl = game.Workspace["Cube Template"]:Clone()
cl.Name = "Cube"
cl.Parent = game.Workspace
cl.Anchored = false
cl.CanCollide = true

i tested this so many times, i also tried to do print, nothing worked
this is server script.

1 Like

maybe the script ran before the cube load did u get any errors?

1 Like
  1. This is #help-and-feedback:scripting-support
  2. Where is this script parented?
  3. Any errors?
  4. Are you hungry? I am.
2 Likes
  1. Yeah sorry
  2. In part, click detector too
  3. no errors
  4. yeah im too

no i didnt get any errors in output

1 Like

Can you show the whole script? It might be to do with how you handle the click detection.

1 Like

its actual full script, lol i just started

I assume that’s your issue then. You don’t ever listen for the ClickDetector, you just immediately clone the part, and then the script finishes.

script.Parent.MouseClick:Connect(function()
    ...
end)

Put your code in this event connection, so that it runs every time you click on the ClickDetector.

its doesnt works, i put script into click detector and tested, nothing works(yeah i changed first string too so theres no errors)

make sure ur script is activated

Can I just double check what your code looks like now? And I want to make sure that this script is parented to a ClickDetector, which is parented to the part you want to click on.

script.Parent.MouseClick:Connect(function(plr)
print("v", plr) -- just tested
local cl = game.Workspace["Cube Template"]:Clone()
cl.Name = "Cube"
cl.Parent = game.Workspace
cl.Anchored = false
cl.CanCollide = true
end)

taketheLLLL

1 Like

If you’re sure the code runs perfectly fine without errors, can you try to offset the part when you spawn it?

you mean just do wait()? i dont think that gonna work, cuz theres no errors in output(sorry if i dont understand you right)

No, I meant it’s position, to make sure it’s not somehow getting stuck inside the original.
For example, set it to the player’s position like this:

cl.Position = plr.Character.PrimaryPart.Position
local ClickDetector = script.Parent
local Cube = game.Workspace["Cube Template"]

local function onClicked()

	local Clone = Cube:Clone()
	
	Clone:Clone()

	Clone.Position = Cube.Position + Vector3.new(0, 10, 0) -- Position
	
	Clone.Name = "Cube"
	Clone.Parent = game.Workspace
	Clone.Anchored = false
	Clone.CanCollide = true
	
end

ClickDetector.MouseClick:Connect(onClicked)

nothing changed, cube dont even added

doesnt work, no any errors in output

That’s not true because I tested it and it works.

Insert a Part. Put a ClickDetector in it. Put a Script in the ClickDetector.

Make sure you have a Part in the Workspace called “Cube Template”

then why it dont works with my :skull:
still dont works