Top.Mail.Ru
Ответы

Не работает скрипт в роблокс студио

Делаю с друзьями игру в роблокс студио, щас делаю скрипт на бег со стаминой, и вот с какой проблемой я столкнулся

По дате
По рейтингу
Аватар пользователя
Ученик
1мес

Замени UserInputStreamService на UserInputService. А в общем попробуй этот код local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local sprintSpeed = 24
local walkSpeed = 16
local stamina = 6
local isSprinting = false

local player = Players.LocalPlayer

local function handleSprint(input, gameProcessed)
if gameProcessed then return end

if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
isSprinting = true

while isSprinting and stamina > 0 do
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.WalkSpeed = sprintSpeed
end
stamina = stamina - 1
wait(1)
end

-- Восстановление выносливости
while not isSprinting and stamina < 6 do
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.WalkSpeed = walkSpeed
end
stamina = stamina + 1
wait(1)
end
end
end
end

local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
isSprinting = false
end
end
end

UserInputService.InputBegan:Connect(handleSprint)
UserInputService.InputEnded:Connect(inputEnded)

-- Инициализация скорости при загрузке
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").WalkSpeed = walkSpeed
end)