You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make the player’s camera follow where he is pointing his mouse -
What is the issue? Include screenshots / videos if possible!
I can’t seem to make the camera follow the mouse’s position. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking at the dev forums and topics similar to it and even YouTube videos.
local userinput = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local function KeyDown()
return userinput:IsKeyDown(Enum.KeyCode.J)
end
local debounce = false
local canTouch = false
local Mouse = Player:GetMouse()
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local RootPart = character:WaitForChild("HumanoidRootPart")
local RS = game:GetService("RunService")
--local Player = game:GetService("Players").LocalPlayer
local controls = require(Player.PlayerScripts.PlayerModule):GetControls()
function beginLooking(input, gameproccessed)
if gameproccessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.J and debounce == false then
print("hi")
local MoveMouseFunction
MoveMouseFunction = Mouse.Move:Connect(function()
local direction = (Mouse.Hit.p - character.HumanoidRootPart.Position) * Vector3.new(1,1,1)
character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + direction)
if not KeyDown() then
MoveMouseFunction:Disconnect()
end
end)
end
end
end
function beginAttack(input, gameproccessed)
if gameproccessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.J and canTouch == false then
canTouch = true
print("Iknow")
game.ReplicatedStorage.FireVortex:FireServer()
local BP = Instance.new("BodyPosition")
BP.D = 250
BP.MaxForce = Vector3.new(1e5,0,1e5)
BP.P = 1e4
BP.Position = RootPart.Position
local BG = Instance.new("BodyGyro")
BG.CFrame = RootPart.CFrame
BG.D = 250
BG.MaxTorque = Vector3.new(1e5,0,1e5)
BG.P = 1e4
BG.Parent = RootPart
local RSconn
RSconn = RS.Heartbeat:Connect(function()
BG.CFrame = CFrame.new(RootPart.Position,Mouse.Hit.p)
end)
--controls:Disable()
--[[userinput.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.J then
RSconn:Disconnect()
BG:Destroy()
return
end
end)--]]
wait(7)
--controls:Enable()
canTouch = false
BP:Destroy()
BG:Destroy()
RSconn:Disconnect()
end
end
end
userinput.InputBegan:Connect(beginLooking)
userinput.InputEnded:Connect(beginAttack)