When I try to use FindFirstDescendant for my movement script, I get an error telling me it isn’t enabled, any ideas how to fix this?
I’ve already tried using “FindFirstChild(“Weight”, true)” like the other posts on this issue have suggested, but that leaves me with another even weirder bug that glitches out my whole game.
Heres my whole script:
--Services--
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--References--
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
--Skill Values--
local agility = character.SkillValues.Agility.Value
--EquippedWeight--
local helmetWeight = character:FindFirstDescendant("HelmetWeight")
local chestplateWeight = character:FindFirstDescendant("ChestplateWeight")
local greavesWeight = character:FindFirstDescendant("GreavesWeight")
local weaponWeight = character:FindFirstDescendant("WeaponWeight")
local helmetWeightValue = helmetWeight.Value
local chestplateWeightValue = chestplateWeight.Value
local greavesWeightValue = greavesWeight.Value
local weaponWeightValue = weaponWeight.Value
local combinedWeight = helmetWeightValue + chestplateWeightValue + greavesWeightValue + weaponWeightValue
--Movement Variables--
local baseSpeed = 16
local modifiedSpeed = baseSpeed * (agility * 0.15) / (combinedWeight)
local walkSpeed = modifiedSpeed * 1
local sprintSpeed = modifiedSpeed * 2
local crouchSpeed = modifiedSpeed * 0.5
local currentSpeed = character.Humanoid.MoveDirection.Magnitude
--Basic Movement--
--Walking--
local function setWalkSpeed()
print("player spawned")
character.Humanoid.WalkSpeed = walkSpeed
print("Set walk speed")
end
--Sprinting (PC)--
local playerIsSprinting = false
local function beginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyCode = input.KeyCode
if keyCode == Enum.KeyCode.LeftShift then
if character.Humanoid.MoveDirection.Magnitude > 0 then
print("player pressed shift")
playerIsSprinting = true
character.Humanoid.WalkSpeed = sprintSpeed
print("player is sprinting")
end
end
end
end
end
local function endSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyCode = input.KeyCode
if keyCode == Enum.KeyCode.LeftShift then
print("player stopped pressing shift")
playerIsSprinting = false
character.Humanoid.WalkSpeed = walkSpeed
print("player is no longer sprinting")
end
end
end
end
local function stopSprintWhenStoppedWalking()
if playerIsSprinting == true and localPlayer.Character.Humanoid.MoveDirection.Magnitude <= 0 then
print("player stopped pressing shift")
playerIsSprinting = false
localPlayer.Character.Humanoid.WalkSpeed = walkSpeed
print("player is no longer sprinting")
end
end
UIS.InputBegan:Connect(beginSprint)
UIS.InputEnded:Connect(endSprint)
RunService.RenderStepped:Connect(stopSprintWhenStoppedWalking)
Players.LocalPlayer.CharacterAdded:Connect(setWalkSpeed)