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

How can I adapt the movement code in my script to work in a LocalServer?

Asked by 6 years ago
Edited 6 years ago
local player = game.Players.LocalPlayer
local Humanoid = player.Character:FindFirstChild("Humanoid")
if Humanoid then
    Humanoid.AutoRotate = false
end

local jumping = false
local crouch = false
local leftValue, rightValue = 0, 0

if script.Parent.HumanoidRootPart.Orientation.Y == 0 then
--[[lots of checks to figure out what animation to play based on input]]
elseif script.Parent.HumanoidRootPart.Orientation.Y == 180 or -180 then
--[[lots of checks to figure out what animation to play based on input except they're all for when the character faces right]]
end
local function onUpdate()
    if player.Character and player.Character:FindFirstChild('Humanoid') then
        if jumping then
                wait(.083)
                if animtrack623.IsPlaying == false then
                    Humanoid.Jump = true
                    local moveDirection = rightValue - leftValue
                    player.Character.Humanoid:Move(Vector3.new(0,0,moveDirection), false)
            end
        elseif crouch == true or anyattackanimation.IsPlaying == true then
            player.Character.Humanoid:Move(Vector3.new(0,0,0), false)
        elseif crouch == false then
            local moveDirection = rightValue - leftValue
            player.Character.Humanoid:Move(Vector3.new(0,0,moveDirection), false)
        end
    end
end

This code is part of a ControlScript I made that handles movement, jumping, and an entire attack command and animation system that I have in my game. However, whenever I try to run the script in a server, none of the movement code works, and the attack system is hampered because it can't find out what direction the character is facing. I've been stuck trying to figure this out for a while, and I've not gotten anything that works, partially because I also have it in StarterCharacterScripts when it should be in StarterPlayerScripts so it can override the default ControlScript. How can I fix the code above so that it works in a server, and if possible,so that it can function in PlayerScripts rather than in the character?

Answer this question