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

Error cloning cookies to workspace?

Supposed to Clone a cookie on the workspace and teleport it to the specified coordinates. Every 0.5 seconds.

enable = true

script.Parent.Touched:connect(function(hit)

while enable do
	local Cookie = game.ReplicatedStorage.Cookie
	local copy = Cookie:Clone()
	copy.Parent = game.Workspace
		copy.Position.CFrame = CFrame.new(2.737, 4.2, 6.376)
	
	enable = false
	wait(0.5)
	enable = true
	end
end)

Errors

Attempt to call a nil value

Position is not a valid member of Tool

4 comments

0

p.s if this is what i think it is(not snippet from a larger code), u dont need the enable there

0

also it might be that u didnt add a debounce

0

wait i think i got it

0

can you give me a cookie

1 answer

probability 1:

assuming that copy is a tool and copy.Position is an Object, it is possible that copy.Position had not loaded at the time u wanted to set its CFrame and thus u cannot define its CFrame. This can be solved(i hope) by waiting for said Position, like so:

enable = true

script.Parent.Touched:connect(function(hit)

while enable do
    local Cookie = game.ReplicatedStorage.Cookie
    local copy = Cookie:Clone()
    copy.Parent = game.Workspace
	local pos = copy:FindFirstChild("Position") or copy:WaitForChild("Position")
        copy.Position.CFrame = CFrame.new(2.737, 4.2, 6.376)

    enable = false
    wait(0.5)
    enable = true
    end
end)

probability 2:

assuming copy.Position is not an Object(which i highly doubt), it would be invalid to put copy.Position.CFrame. I am unable to solve this in such a case but rather request u learn more abt CFrames(it is not a member of position understand?)

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