Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix humanoid temporary player look the direction they're pointing?

Asked by
Neon_N 104
5 years ago

I copied the script from people that gave me solution but this script only work sometime. I need another solution..

-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

-- 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 = 90
        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)
0
You already have the player character and mouse defined before the event. No need to write duplicate code. Also I suggest you rename the Remote variable to something with a bit more meaning, like FireEvent or something. User#24403 69 — 5y
0
Ok. Neon_N 104 — 5y

Answer this question