local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Mouse = player:GetMouse()
local primary = char.PrimaryPart
local connection = game:GetService("RunService").RenderStepped:Connect(function()
local MouseDirection = Mouse.UnitRay.Direction
--primary.CFrame.LookVector = MouseDirection
print(MouseDirection)
char:SetPrimaryPartCFrame(CFrame.new(char:GetPrimaryPartCFrame().Position, Mouse.UnitRay.Direction * 1000))
end)
if humanoid.Health > 0 then
connection()
elseif humanoid.Died then
connection:Disconnect()
end
In the output im just printing MouseDirection and i am just holding W im not sure why im going up in the air im trying to make the char face the mouse pos making a game that utilizes this mechanic.
Also it doesn’t disconnect if the player dies it just says model does not exist and it doesn’t reload when the player dies its located in starterplayer scripts
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Mouse = player:GetMouse()
local primary = char.PrimaryPart
local connection
connection = function()
game:GetService("RunService").RenderStepped:Connect(function()
local MouseDirection = Mouse.UnitRay.Direction
--primary.CFrame.LookVector = MouseDirection
print(MouseDirection)
char:SetPrimaryPartCFrame(CFrame.new(char:GetPrimaryPartCFrame().Position, Mouse.UnitRay.Direction * 1000))
end)
end
humanoid.Died:Connect(function()
connection:Disconnect()
end)