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

Stuck on why clone script will not work. Should be very easy?

Asked by 6 years ago
local part = script.Parent
local clickdetector = part:WaitForChild("ClickDetector")

clickdetector.MouseClick:connect(function(Player)
    script.Parent.Parent:FindFirstChild("funraft"):clone ()
    position = ("272.95, -49.616, 994.277")
    end)

Trying to figure out how to resolve this issue. I have made a raft and I want there to be a clone button, so if you click on the clone button then the raft will "respawn" but it is actually an entirely new raft while the other raft is still going down the waterfall. Help would be appreciated! let me know if this doesn't make any sense it is kind of confusing to put into words. :)

0
It’s Clone not clone. User#19524 175 — 6y
1
thanks any idea how to do the position? DevSplit 11 — 6y
0
You make a position using Vsctor3.new. So: Vector3.new(272.95, -49.616, 994.277). No strings. User#19524 175 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

First of all, your parenthesis for Clone is incorrect as they shouldn't be spacing between both words. Also connect is a deprecated form of Event Connections, instead use Connect. Second of all, Roblox can't spawn the object you want in the position you have given us as you have not assigned it to the property of the part and haven't give the position a Vector3. Therefore by default the part will spawn at Co-ordinates 0, 0, 0. Here is your script redone for it to actually work.

local part = script.Parent
local clickdetector = part:WaitForChild("ClickDetector")

clickdetector.MouseClick:Connect(function(Player)
    local cloned_part = script.Parent.Parent:FindFirstChild("funraft"):Clone()
    cloned_part.Position = Vector3.new(27295, -49.616, 994.227)
    cloned_part.Parent = workspace --Or Wherever you want to parent it.
    end)
Ad
Log in to vote
1
Answered by
Ap_inity 112
6 years ago
Edited 6 years ago

First of all, you are using 2 unused/useless variables, such as: "part" and "Player".

local clickdetector = script.Parent:WaitForChild("ClickDetector") -- Instead of making a new variable, just use the content from the variable inside of it.
clickdetector.MouseClick:connect(function() -- You don't need a variable inside of the function.

Secondly, "clone" is written "Clone", and you don't need a space between the brackets, like so: "Clone()"

Thirdly, "position" should be paired with "Vector3.new()". Position is not a variable, here is an example of how you should use Vector3:

script.Parent.Position = Vector3.new([newPos])

And lastly, any type of number doesn't need double commas.

I have recreated your script, it should look like this:

local clickdetector = script.Parent:WaitForChild("ClickDetector")

clickdetector.MouseClick:connect(function()
    local raft = script.Parent.Parent:FindFirstChild("funraft"):Clone()
    raft.Position = Vector3.new(272.95, -49.616, 994.277)
end)

Please upvote if this helped you. If you come across any errors, please let me know by typing up a comment.

Answer this question