Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am making a cloning script when a button is clicked help please?

I have a ball that you go into and when you click this button its meant to clone it and place it at the cords but it doesn't someone please help me. it clones if I take out the clicked function but it just keeps multiplying which I don't want I only want it to multiply once when button is clicked reply as soon as possible please. I want it to clone the block but also the script that puts the player in ball which is in the ball part. I am not very good with scripts so if you could at least tell me what I did wrong and where to put things i might be able to fix it.

function onClicked()
	while true do
			model = game.Workspace.Ball.Ball:clone()  
			model.Parent = game.Workspace.new_ball
			model.Position = Vector3.new(-50,5,-64)
			print("cloned")
			wait(10)
	end
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)`

I put the script in the clickdetector which is in the button. The ball which I want to clone is in the same folder with the button. Thank you to anyone that helps.

I tweaked it a bit because I found script analysis and I removed the while true part but it still doesn't work

function onClicked()
	script.Parent.ClickDetector.MouseClick:Connect(onClicked)
	game.Workspace.Ball.Ball:clone() 
	local Parent = game.Workspace.new_ball
	local Position = Vector3.new(-50,5,-64)
	print("cloned")
end

2 comments

0

tag me if my solution in the chat does not work (u can tag me in the comments)

0

@MarkoFANTASTINE1, @thecelestialcube, @2_MMZ I removed the while true bit and the end which went with that but it still don't work any ideas?

4 answers

✓ Accepted answer

Here's what you need to do:

function onClicked()
while true do
wait(10)
local model = game.Workspace.Ball.Ball:Clone()
model.Parent = game.Workspace.["new_ball"]
model.Position = Vector3.new(-50,5-64)
print("Ball has been cloned!")
      end
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)

1 comment

0

sorry it didnt work @2_MMZ

If you only want it to clone once, then why are you using a while true loop? If the script is in the ball part, then it'll also clone. The rest of the code looks good though.

function onClicked()
	local model = game.Workspace.Ball.Ball:Clone()
	model.Parent = game.Workspace.new_ball
 	model.Position = Vector3.new(-50,5,-64)
	print("cloned")
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

This should work. You should also make sure that the model you are cloning has cancollide set to true.

3 comments

0

sorry it didn't work @thecelestialcube

0

If you click the button do you see cloned in the output?

0

@thecelestialcube in the output it does not say cloned or when script analysis is run their are no warnings or errors.

The "while true do" loop constantly loops the code written inside it (between the word "do" and "end").

model = game.Workspace.Ball.Ball:clone() 
model.Parent = game.Workspace.new_ball
model.Position = Vector3.new(-50,5,-64)
print("cloned")
wait(10)

if you want the code above to execute every time you click on the object you referenced (script.Parent) - you can simply REMOVE the "while true do" loop.

Here is the full code if you don't know what I mean:

function onClicked()
	model = game.Workspace.Ball.Ball:clone() 
	model.Parent = game.Workspace.new_ball
	model.Position = Vector3.new(-50,5,-64)
	print("cloned")
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

1 comment

0

sorry it didnt work @MarkoFANTASTINE1

local endPosition = Vector3.new(-1595, 6190.496, -67)
function onClicked()
	local clone = game.Workspace.Finished.Ball.Ball:Clone()
	clone.Parent = game.Workspace.Finished.new_ball
	print("cloned1")
	clone.Position = Vector3.new(-1595, 6180.496, -67)
	clone.Anchored = false
	print("cloned2")
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

This discussion is preserved as it was. New answers, comments, and votes are closed.