CFrame not setting

For some reason my output is erroring: ReplicatedStorage.Modules.StormModule:11: invalid argument #1 to ‘new’ (Vector3 expected, got number) and I want to set the CFrame or Position to somewhere random, which is already set using the parameter pos (set in diff script) Thanks for helping!

function StormModule.Spawn(pos)
	local Supercell = ReplicatedStorage.Replicables.Supercell
	local SupercellClone = Supercell:Clone()
	SupercellClone.Parent = workspace.Storms
	SupercellClone.Name = "Supercell"
	Supercell.CFrame = CFrame.new(pos)
end

Hello again!

Make sure you post all relevant code. Clicking on the error will lead you to line 11, which is giving an invalid argument for the new constructor, which I’m assuming pos is actually a number, not a Vector3 based off the error message.

1 Like

line 11 is Supercell.CFrame = CFrame.new(pos) supercell is a model, I may have to use primary part again but it would interfere with another function that makes it.

pos is a number yes, in another script theres math.random for x, y, and z seperatly, then put into the parameters.

1 Like
while true do
 RandomDirectionSpeed = math.random(-100, 300)
 x = math.random(-200, 200)
 y = math.random(27.549,27.549)
 z = math.random(-200, 200)

	StormModule.Spawn(x,y,z)
	StormModule.MoveAndDissipate(RandomDirectionSpeed, 10, 3)  --// WindDirection, WindSpeed, Time
	
	wait(3)
end
``` this is the script for intializing the module
1 Like

Assuming it is the same structure as your previous post:

Workspace
    Storm (Folder)
        Supercell (Model)

You want to do manipulation on SupercellClone, not Supercell (which is the original in the ReplicatedStorage).

If you are passing in 3 numbers to your function call, you would have to do this instead:

function StormModule.Spawn(x, y, z)
    -- instead of pos
end
1 Like

oh i got ya lol that was a dumb mistake on my part

1 Like

CFrame is not a valid member of Model “ReplicatedStorage.Replicables.Supercell” is my new error, the code line says: Supercell.CFrame = Vector3.new(x,y,z)

1 Like

Remember, documentation is your best friend. Models do not have a CFrame property. If you want to manipulate it’s position without relying on a PrimaryPart (or any BasePart for that matter), refer to the previous post where I showed you about PivotTo and GetPivot.

-- use SupercellClone, not Supercell
SupercellClone:PivotTo(CFrame.new(x, y, z))

Edit:

The CFrame property only accepts a CFrame.

5 Likes

thank you so much! I hadnt worked with positioning models and thats a big learning experience for me, I appreciate your help on both parts. Have a good night or day idk its midnight for me and im slowly going insane

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.