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

How do I go around fixing this CFrame error in my script?

I'm trying to make a touch triggered script which launches a firework, when you walk onto a Unioned sphere. When the script inside the sphere reaches this point:

local rocket = game:GetService("ServerStorage").FireWork:Clone()
			rocket.Parent = script.Parent.Parent
			rocket.Anchored = false
			rocket.CFrame = CFrame.new(script.Parent.CFrame.p) + CFrame.new(0,2,0)

I get an error which says: 20:19:48.684 - Workspace.Confetti.Ball.Script:11: bad argument #2 to '?' (Vector3 expected, got CFrame) And I know it has something to do with the way I have written the CFrame but I don't know how to fix it! any help?

2 answers

Try this one out

local rocket = game:GetService("ServerStorage").FireWork:Clone()
rocket.Parent = script.Parent.Parent
rocket.Anchored = false
rocket.CFrame = rocket.CFrame * CFrame.new(0, 1, 0)

also if your making a firework you might want to put a for loop and also keep it anchored because CFrame ignores anchoring. So if you want a loop say for example it to go up smoother you would do:

local rocket = game:GetService("ServerStorage").Firework:Clone()
rocket.Parent = script.Parent.Parent
rocket.Anchored = true
for i=0, 1, 0.1 do
	wait(0.1)
	rocket.CFrame = rocket.CFrame * CFrame.new(0, 0.1, 0)
end

this code will also make it look smoother, however if you don't want it to loop and just want a fix for the CFrame the top one is your best option :)

1 comment

0

not quite what i meant, the firework is in serverstorage, it gets cloned above a sphere and it has BodyVelocity in it which then explodes, the CFrame was to spawn above the sphere/ball

View CFrame information at http://wiki.roblox.com/index.php?title=CFrame

When you do rocket.CFrame = CFrame.new(script.Parent.CFrame.p) + CFrame.new(0,2,0) You attempt to add CFrames, but this operation is not allowed. You can only multiply CFrames because they are matrices.

Here is the simple fix:

rocket.CFrame = script.Parent.CFrame * CFrame.new(0,2,0)

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