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

Am I not using CFrame Correctly?

I am trying to move a model after it is placed in a spot but I keep getting an error message that says CFrame isn't a member of the model. I have also tried using Position instead of CFrame and it doesn't work either. Can anyone find what I'm doing wrong? To be clear, I am trying to move CSprout's position or CFrame by 10 studs in one direction, but the problem is it doesn't recognize CFrame. Thanks!

	
	
	function Plant()
local seed = script.Parent:FindFirstChild("Wheatstalk")
local seed2 = script.Parent:FindFirstChild("Wheatstalk2")
local seed3 = script.Parent:FindFirstChild("Wheatstalk3")
local seed4 = script.Parent:FindFirstChild("Wheatstalk4")
local seed5 = script.Parent:FindFirstChild("Wheatstalk5")
local seed6 = script.Parent:FindFirstChild("Wheatstalk6")

	local position = seed.Position
	local name = "WheatSp2"
	local Sprout = game.Lighting.Agriculture.Sprouts2:FindFirstChild(name)
	local CSprout = Sprout:Clone()
	local position = seed.Position

	seed:remove()
	seed2:remove()
	seed3:remove()
	seed4:remove()
	seed5:remove()
	seed6:remove()
	
	CSprout.Parent = game.Workspace
	CSprout:MoveTo(position)
	CSprout:MakeJoints()
	
	
	local x = CSprout.Wheatstalk.CFrame.x
	local y = CSprout.Wheatstalk.CFrame.y
	local z = CSprout.Wheatstalk.CFrame.z
	CSprout:SetPrimaryPartCFrame(x + 10,y,z)
	
end

wait(20)
Plant()
print("planted")

1 comment

0

You can't use CFrame on a model. Either move the model with the MoveTo function, or use it's primary part CFrame.

1 answer

✓ Accepted answer

1st Do not use 'Lighting' to store models, we have ReplicatedStorage for this.

A Model object no longer has the property CFrame.

A Model can have a lot of parts so you must set the new CFrame for each of its children, Roblox has given a function which will change all of the Moldels CFrame called SetPrimaryPartCFrame.

6 comments

0

Yeah I know i should be using RS for storing but it would take forever to change all my scripts over so maybe one day. Thanks for the answer! How do I set the primary part for a model?

0

CSprout:SetPrimaryPartCFrame( the CFrame here)

0

Now the error is "Unable to cast double to coordinateframe", on the line "CSprout:SetPrimaryPartCFrame(x + 10,y,z)". Can I not use the variables x,y, and z or is the problem that I put the x + 10 as the x coordinate?

0

You still need to create a new CFame CSprout:SetPrimaryPartCFrame( CFrame.new( data here ))

0

Awesome, thanks!

0

Np

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