The script below is Localscript and is in StarterCharacterScripts.
-- Services -- local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputService = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") -- Variables -- local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Remote = game.ReplicatedStorage.RemoteEvents.FireBallEvent local Mouse = plr:GetMouse() -- Settings -- local Debounce = true local Key = 'Q' local Animation = Instance.new("Animation") Animation.AnimationId = 'rbxassetid://2593868235' UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then Debounce = false local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() -- View -- local player = game.Players.LocalPlayer local character = player.Character local torso = character.HumanoidRootPart local mouse = player:GetMouse() local ev = mouse.Move:Connect(function() character.Humanoid.AutoRotate = false torso.CFrame = CFrame.new(torso.Position, mouse.Hit.p*Vector3.new(1,0,1) + torso.Position*Vector3.new(0, 1, 0)) end) wait(.5) ev:Disconnect() character.Humanoid.AutoRotate = true Remote:FireServer(Mouse.Hit) wait(2) Debounce = true end end)
And the script below is what I tried to make player turn more smoothly.
-- Services -- local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputService = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") -- Variables -- local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Remote = game.ReplicatedStorage.RemoteEvents.FireBallEvent local Mouse = plr:GetMouse() -- Settings -- local Debounce = true local Key = 'Q' local Animation = Instance.new("Animation") Animation.AnimationId = 'rbxassetid://2593868235' UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then Debounce = false local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() -- View -- local player = game.Players.LocalPlayer local character = player.Character local torso = character.HumanoidRootPart.Position local mouse = player:GetMouse() local ev = mouse.Move:Connect(function() character.Humanoid.AutoRotate = false local part = CFrame.new(torso.Position) local goal = {} torso.CFrame = CFrame.new(Mouse.Hit.p*Vector3.new(1,0,1) + torso.Position*Vector3.new(0, 1, 0)) local tweenInfo = TweenInfo.new(5) local tween = TweenService:Create(part, tweenInfo, goal) tween:Play() wait(3) ev:Disconnect() character.Humanoid.AutoRotate = true Remote:FireServer(Mouse.Hit) wait(2) Debounce = true end) end end)
Yep it didn't work. I don't even know how TweenService work in the first place. I need a solution for this thing to work.
If you want to make the character turn wherever the mouse is, I recommend a BodyGyro. Since BodyGyro is a BodyMover, you can put it in a local script because the movement will not need a RemoteEvent/RemoteFunction to transfer it to the entire server. I use BodyGyros for things like what you're trying to do, and it works out really smooth.
-- Services -- local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputService = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") -- Variables -- local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Remote = game.ReplicatedStorage.RemoteEvents.FireBallEvent local Mouse = plr:GetMouse() -- Settings -- local Debounce = true local Key = 'Q' local Animation = Instance.new("Animation") Animation.AnimationId = 'rbxassetid://2593868235' UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then Debounce = false local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() -- View -- local player = game.Players.LocalPlayer local character = player.Character local torso = character.HumanoidRootPart local mouse = player:GetMouse() local bg = Instance.new("BodyGyro") bg.Parent = torso bg.D = 135--Edit this to see basically see how fast it takes to reach the Mouse Position. The higher number is slower, lower is faster. bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge) local ev = mouse.Move:Connect(function() character.Humanoid.AutoRotate = false bg.CFrame = CFrame.new(torso.Position,mouse.Hit.Position) end) wait(.5) ev:Disconnect() bg:Destroy() character.Humanoid.AutoRotate = true Remote:FireServer(Mouse.Hit) wait(2) Debounce = true end end)