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

Why does this script not allow me to move?

Asked by
yelsew 205 Moderation Voter
8 years ago

I don't think I see anything that prevents the character from moving. I am not able to jump, walk, or anything that involves me having to press a key to move my character. The script is in StarterPlayerScripts, and it is a local script.

local player = game.Players.LocalPlayer
local gyro = nil
local flashlight = nil
local mouse = player:GetMouse()
mouse.TargetFilter = game.Workspace
local runService = game:GetService("RunService")

local function onCharacterAdded(character)
    local torso = character:WaitForChild("Torso")
    gyro = Instance.new("BodyGyro", torso)
    gyro.P = 1000000
    gyro.MaxTorque = Vector3.new(0, 10000, 0)
    flashlight = Instance.new("PointLight", torso)
end

local function isnan(x) return x ~= x end

local function onRenderStep()
    if gyro then
        local mouseHit = mouse.Hit.p
        if not (isnan(mouseHit.X) or isnan(mouseHit.Y) or isnan(mouseHit.Z)) then
            gyro.CFrame = CFrame.new(player.Character.Torso.Position, mouseHit)
        end
    end
end

while not player.Character do wait() end
onCharacterAdded(player.Character)
player.CharacterAdded:connect(onCharacterAdded)

runService:BindToRenderStep('TrackMouse', Enum.RenderPriority.Input.Value, onRenderStep)

If you can find any way to allow the character some movement, please let me know.

Answer this question