Player look script

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


https://gyazo.com/e4cfd98bd576ec9caca663efd0207466

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

Would doing?:

local connection
connection = function()
end

Humanoid.Died:Connect(function)
    connection:Disconnect() 
end)

The connection won’t run if i do that i need to run it if it the player is alive

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)

Did it work…? :face_with_raised_eyebrow:

30 chars man…

Nope it didn’t

30 chars loooooooooooooooooooooooooooo

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)

Do

local connection
connection = game:GetService("RunService").RenderStepped:Connect(function()
    - - code
end

-- in the died function just disconnect it.

On mobile, big oof

alright will try
30 char limit

1 Like

You should put the script in StarterCharacterScripts instead of StarterPlayerScripts and
write the script something like this: