Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this CFrame code work?

Asked by 8 years ago

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.

1
Just change the last parts of the CFrame to Vector3.new() instead CFrame.new() TheDeadlyPanther 2460 — 8y
0
YOU JUST FIXED IT! Here, take a rep fro your service. NeonicPlasma 181 — 8y

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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().

Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question