Hello my guys, my player dosnt running and i dont know what the problem!
The peculiarity of my script is that it takes information about stamina from the player himself in the PlayerStats folder, but for some reason nothing happens
Another script creates an IntValue inside the player called Stamina and its default value is 500.
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local function updateStamina(player)
local playerStats = player:WaitForChild("PlayerStats")
if playerStats then
local stamina = playerStats:WaitForChild("Stamina")
if stamina then
local currentStamina = stamina.Value
if currentStamina > 0 then
local walkSpeed
if currentStamina >= 400 then
walkSpeed = 23
elseif currentStamina >= 300 then
walkSpeed = 21
elseif currentStamina >= 200 then
walkSpeed = 19
elseif currentStamina >= 100 then
walkSpeed = 16
else
walkSpeed = 14
end
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = walkSpeed
stamina.Value = currentStamina - 5
else
player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 14
end
stamina.Value = math.min(currentStamina + 1, 500)
else
player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 14
end
else
warn("Stamina not found for player", player.Name)
end
else
warn("PlayerStats not found for player", player.Name)
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local playerStats = player:WaitForChild("PlayerStats", math.huge)
if playerStats then
local stamina = playerStats:FindFirstChild("Stamina")
if stamina then
while wait(1) do
updateStamina(player)
end
else
warn("Stamina not found for player", player.Name)
end
else
warn("PlayerStats not found for player", player.Name)
end
end)
end)