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

Model rotating where you look? [Help]

Asked by
Sougood -10
5 years ago
Edited 5 years ago

Hello. So, I am making game, where will be pets, but. The pet is model, with PrimaryPart, not a mesh. So I don't know how to make it rotate depending on where you look.

I have made this, but it only rotates in half and then goes back.

local Pet = script.Parent
local Move = script.Parent:WaitForChild('Move')

Move.OnServerEvent:connect(function(Player)
    if workspace[Player.Name] then
        local Head = workspace[Player.Name]:FindFirstChild('Head')
        if Head then
            Pet:SetPrimaryPartCFrame(CFrame.new(Head.CFrame.X + 1,Head.CFrame.Y + 2,Head.CFrame.Z + 1))
            Pet:SetPrimaryPartCFrame(Pet.Hitbox.CFrame * CFrame.Angles(0,Head.CFrame.lookVector.Z,0))
        end
    end
end)

1 answer

Log in to vote
-1
Answered by
Delude_d 112
5 years ago
Edited 5 years ago

local Pet = script.Parent local Move = script.Parent:WaitForChild('Move')

Move.OnServerEvent:connect(function(Player) if workspace[Player.Name] then local Head = workspace[Player.Name]:FindFirstChild('Head') while Head do wait() Pet:SetPrimaryPartCFrame(CFrame.new(Head.CFrame.X + 1,Head.CFrame.Y + 2,Head.CFrame.Z + 1)) Pet:SetPrimaryPartCFrame(Pet.Hitbox.CFrame * CFrame.Angles(0,Head.CFrame.lookVector.Z,0)) end end end)

0
This should make it so that the pet always rotates to where you're looking. Delude_d 112 — 5y
0
-1: This is not what he asked, and you would make the script hang because your loop contains no wait... SulaymanArafat 230 — 5y
0
oof, i keep forgetting the wait Delude_d 112 — 5y
0
it is alright but still it didnt fix what he asked SulaymanArafat 230 — 5y
0
Thanks for help. But it's not what am I asking for. Sougood -10 — 5y
Ad

Answer this question