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

Why isnt this function executing?

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

1 comment

0

This should have an error.

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks alot, i think im going to get my job simulator working!

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