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

Why isnt this function executing?

Asked by
ARTEK22 135
8 years ago

(I WROTE THAT TITLE BECAUSE OTHER TITLES DIDN'T WORK) So, this is just a script what dosen't work, dosen't even show an error. Here it is:

local boxclone = game.ReplicatedStorage.Box:Clone()
local box = game.ReplicatedStorage.Box
function clicked()
    box:Clone()
    boxclone.Position = game.Workspace.Model.epia.Position - Vector3.new(0, 5, 0)
end

script.Parent.ClickDetector.mouseClick:connect(clicked)
0
This should have an error. BlueTaslem 18071 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

You're not parenting your object anywhere after it's cloned. As mentioned on the wiki, cloned objects will not be automatically parented to a location. You must parent them manually after getting a reference to the cloned object.


You're also not doing anything on line 4 by saying box:Clone(). That's just copying the object every time the function executes, parenting it to nil immediately.


You're also saying mouseClick instead of MouseClick. Lua is case-sensitive, and sees both of those indices as different representations.

Solution

Simply just create a variable for your cloned object, and parent it:

local box = game.ReplicatedStorage.Box

script.Parent.ClickDetector.MouseClick:connect(function()
    local boxClone = box:Clone() -- Create a variable for the cloned object
    -- Your code
    boxClone.Parent = workspace -- Parent it afterwards
end)

Let me know if you have any questions.

0
Thanks alot, i think im going to get my job simulator working! ARTEK22 135 — 8y
Ad

Answer this question