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

Why won't this CFrame code work?

So my friend, KiHeros, told me that I should use CFrame. The only problem is, I DOESN'T WORK. Here is the script:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		char.Humanoid.WalkSpeed = 16
	for _, thing in pairs(char:GetChildren()) do
		if thing.ClassName == "Hat" then
			print("doi")
			thing:remove()
		end
	end
  	local torso = char.Torso
    local backTarget = game.ServerStorage.Target:Clone()
    local frontTarget = game.ServerStorage.Target:Clone()
    frontTarget.CFrame = torso.CFrame + CFrame.new(0, 0, 1.2)
    frontTarget.Parent = char
    backTarget.CFrame = torso.CFrame - CFrame.new(0, 0, 1.2)
    backTarget.Parent = char
    --[[
    The problem is that we can't actually get the target to stick to the torso. AND WE ARE USING A UNION AS A TARGET. I CANT WELD UNIONS. IMPOSSIBLE.
   --]]
      repeat
          frontTarget.CFrame = torso.CFrame + CFrame.new(0, 0, 1.2)
          frontTarget.Rotation = torso.Rotation + Vector3.new(90, 0, 0)
          backTarget.CFrame = torso.CFrame - CFrame.new(0, 0, 1.2)
   	      backTarget.Rotation = torso.Rotation + Vector3.new(90, 0, 0)
          wait(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
      until player.Character.Humanoid.Health == 0 -- Probably going to be glitchy but try it.
  end)
end)

In my output, I get:

16:26:51.035 - Workspace.Script:13: bad argument #2 to '?' (Vector3 expected, got CFrame) 16:26:51.036 - Script 'Workspace.Script', Line 13 16:26:51.036 - Stack End

Could you help? Thanks.

2 comments

1

Just change the last parts of the CFrame to Vector3.new() instead CFrame.new()

0

YOU JUST FIXED IT! Here, take a rep fro your service.

2 answers

✓ Accepted answer

A CFrame can't be directly added to another CFrame (the first can be transformed relatively by the second by multiplying) but a Vector3 can be added to a CFrame. Instead of writing CFrame.new()+CFrame.new(), write CFrame.new()+Vector3.new().

On several lines you put in CFrame.new() instead of putting this use Vector3.new()

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