#someone help :3
1 messages · Page 1 of 1 (latest)
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
** You are now Level 4! **
I think the small local script should be looking the local player’s sprinting handler script rather than the starterplayer because there is an exception with the WaitForChild statement in the first line
which one???
whats it named TwT
LocalScript
oh btw this is like my 1st time coding
All good 👍
oooohhhhh
it needs to be like
local sprintingHandler = game:GetService("sprintingHandler")
btw the sprinting handler script is a child of the starter player script
the getservice method you are calling cannot be used like that
So let me make this brief:
when the player loads into the game, the starterplayerscripts will be cloned into the player itself
** You are now Level 3! **