-
What do you want to achieve? A script that makes the player face the mouse
-
What is the issue? the player faces the mouse when they key is first pressed but doest continue following it
-
What solutions have you tried so far? none so far
here’s my script:
-- services and variables
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character
local debounce = false
local ShieldEvent = ReplicatedStorage.FloraRemotes:FindFirstChild("FloraShield")
local function toggle(value)
character.Blast.Disabled = value
character.Symphony.Disabled = value
end
local bg
local connection
local onAnim = Instance.new("Animation")
onAnim.AnimationId = "rbxassetid://8483958299"
local loadedAnim = character.Humanoid:LoadAnimation(onAnim)
-- code
UserInputService.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.C and debounce == false then
debounce = true
toggle(true)
ShieldEvent:FireServer("Shield On")
local AnimationTracks = character.Humanoid:GetPlayingAnimationTracks()
for i, track in pairs (AnimationTracks) do
track:Stop()
end
-- this is the part of the script that controls the rotation and etc
bg = Instance.new("BodyGyro", character.HumanoidRootPart)
bg.maxTorque = Vector3.new(math.huge, math.huge, math.huge);
bg.P = 10^7;
bg.D = 100
connection = RunService.RenderStepped:Connect(function()
RunService.RenderStepped:Wait()
local direction = (player:GetMouse().Hit.p - character.HumanoidRootPart.Position) * Vector3.new(1,0,1)
bg.CFrame = CFrame.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + direction)
end)
task.wait(2)
debounce = false
end
end)
UserInputService.InputEnded:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.C then
toggle(false)
connection:Disconnect()
game.Debris:AddItem(bg, .1)
ShieldEvent:FireServer("Shield Off")
end
end)
ReplicatedStorage.FloraRemotes.FloraShieldOn.OnClientEvent:Connect(function()
loadedAnim:Play()
end)
ReplicatedStorage.FloraRemotes.FloraShieldOff.OnClientEvent:Connect(function()
loadedAnim:Stop()
end)