Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

0
tag me if my solution in the chat does not work (u can tag me in the comments) MarkoFANTASTINE1 15 — 3y
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? UNIMAKZIN00 41 — 3y

4 answers

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

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)
0
sorry it didnt work @2_MMZ UNIMAKZIN00 41 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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.

0
sorry it didn't work @thecelestialcube UNIMAKZIN00 41 — 3y
0
If you click the button do you see cloned in the output? thecelestialcube 123 — 3y
0
@thecelestialcube in the output it does not say cloned or when script analysis is run their are no warnings or errors. UNIMAKZIN00 41 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
sorry it didnt work @MarkoFANTASTINE1 UNIMAKZIN00 41 — 3y
Log in to vote
0
Answered by 3 years ago
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)

Answer this question