#someone help :3

1 messages · Page 1 of 1 (latest)

wintry wolf
#

so like im trying to make it so when your stamina gets to 0 it makes text visible but my code isnt working and it says there are no errors TwT
here are the pics:

#

wait

#

1st half of sprinting code:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local SprintSound = script.Parent.Breathing
local CantBreathe = script.Parent.NoBreathing

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

-- Configuration
local maxStamina = 100
local staminaDrainRate = 20 -- per second
local staminaRegenRate = 15 -- per second
local regenDelay = 1.5 -- seconds before regen starts

local walkSpeed = 10
local sprintSpeed = 15

local normalFOV = 50
local sprintFOV = 120
local tweenTime = 0.5

-- Variables
local currentStamina = maxStamina
local sprinting = false
local regenCooldown = 0
local fovTween = nil

-- Functions
local function tweenFOV(toFOV)
if fovTween then
fovTween:Cancel()
end
local goal = { FieldOfView = toFOV }
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
fovTween = TweenService:Create(camera, tweenInfo, goal)
fovTween:Play()
end

#

2nd half of sprinting script:

-- Input
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.LeftShift and not processed then
if currentStamina > 0 then
sprinting = true
SprintSound:Stop()
tweenFOV(sprintFOV)
end
end
end)

UserInputService.InputEnded:Connect(function(input, _)
if input.KeyCode == Enum.KeyCode.LeftShift then
sprinting = false
SprintSound:Play()
regenCooldown = regenDelay
tweenFOV(normalFOV)
end
end)

-- Main Loop
RunService.RenderStepped:Connect(function(deltaTime)
if not character or not character.Parent then
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
return
end

if sprinting and currentStamina > 0 then
    currentStamina -= staminaDrainRate * deltaTime
    humanoid.WalkSpeed = sprintSpeed
    regenCooldown = regenDelay

    if currentStamina <= 0 then
        currentStamina = 0
        sprinting = false
        tweenFOV(normalFOV)
    end
else
    humanoid.WalkSpeed = walkSpeed
end

if regenCooldown > 0 then
    regenCooldown -= deltaTime
else
    if currentStamina < maxStamina then
        currentStamina += staminaRegenRate * deltaTime
        if currentStamina > maxStamina  then
            currentStamina = maxStamina
        end
    end
end

end)

#

and here's my lil script to try to make the text appear:

local sprintingHandler = game:GetService("StarterPlayer"):WaitForChild("Folder"):WaitForChild("SprintingHandler")
local text = script.Parent.catGotYourTongu
local currentStam = sprintingHandler.CurrentStamina
local noBreathing = currentStam <= 0

if noBreathing then
text.Visible = true
end

#

Its not working so yea plz help TwT

maiden iceBOT
#

studio** You are now Level 4! **studio

wintry wolf
teal lantern
wintry wolf
#

whats it named TwT

teal lantern
#

LocalScript

wintry wolf
#

oh btw this is like my 1st time coding

teal lantern
#

All good 👍

wintry wolf
#

oooohhhhh

#

it needs to be like
local sprintingHandler = game:GetService("sprintingHandler")

#

btw the sprinting handler script is a child of the starter player script

teal lantern
#

the getservice method you are calling cannot be used like that

teal lantern
maiden iceBOT
#

studio** You are now Level 3! **studio

teal lantern
#

And each local script will only be run by each individual player

#

So you would need to access the local player’s playerscripts folder to access the sprinting handler

#

Oh wait

#

You only run the if statement once

wintry wolf
#

oh okays

#

ill tell u if it works in a bit!!