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
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)
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.
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)
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)