#script doesnt work after my character dies

1 messages · Page 1 of 1 (latest)

gaunt quest
#

When I press the shift key, the stamina decreases and the amount of stamina is reflected in the size of the StaminaUI. At first, there is no problem, but once the character dies, even if i press the shift key, it doesn't get faster and the StaminaUI doesn't change in size

#

local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local staminaUI = screenGui:WaitForChild("StaminaUI")

local humanoid = character:WaitForChild("Humanoid")

-- 설정 값
local normalSpeed = 16
local sprintSpeed = 28
local staminaRate = 10
local maxStamina = 100
local barMaxWidth = 244

-- 상태 변수
local stamina = maxStamina
local isSprinting = false
local canSprint = true

-- UI 초기화

-- 입력 처리
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
if stamina > 0 and canSprint then
isSprinting = true
end
end
end)

UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isSprinting = false
end
end)

RunService.RenderStepped:Connect(function(dt)
    -- 스프린트 로직
    if isSprinting and canSprint then
        humanoid.WalkSpeed = sprintSpeed
        stamina -= staminaRate * dt
        if stamina <= 0 then
            stamina = 0
            canSprint = false
        end
    else
        humanoid.WalkSpeed = normalSpeed
        if stamina < maxStamina then
            stamina += staminaRate * dt
            if stamina >= 10 then
                canSprint = true
            end
        end
    end

    -- UI 업데이트
    local percent = stamina / maxStamina
    staminaUI.Size = UDim2.new(0, barMaxWidth * percent, 0, 17)
end)
honest jolt
#

format it

#

i cant read

#

anyways, is this ai

#

whatever this is it has to do with uis i see

#

and i understand what the matter is but i dont like ai skids

gaunt quest
#

format it? what do you mean

orchid jay
#

like this jinwoo

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local staminaUI = screenGui:WaitForChild("StaminaUI")

local humanoid = character:WaitForChild("Humanoid")

-- 설정 값
local normalSpeed = 16
local sprintSpeed = 28
local staminaRate = 10
local maxStamina = 100
local barMaxWidth = 244

-- 상태 변수
local stamina = maxStamina
local isSprinting = false
local canSprint = true

-- UI 초기화

-- 입력 처리
UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.KeyCode == Enum.KeyCode.LeftShift then
        if stamina > 0 and canSprint then
            isSprinting = true
        end
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        isSprinting = false
    end
end)

    RunService.RenderStepped:Connect(function(dt)
        -- 스프린트 로직
        if isSprinting and canSprint then
            humanoid.WalkSpeed = sprintSpeed
            stamina -= staminaRate * dt
            if stamina <= 0 then
                stamina = 0
                canSprint = false
            end
        else
            humanoid.WalkSpeed = normalSpeed
            if stamina < maxStamina then
                stamina += staminaRate * dt
                if stamina >= 10 then
                    canSprint = true
                end
            end
        end

        -- UI 업데이트
        local percent = stamina / maxStamina
        staminaUI.Size = UDim2.new(0, barMaxWidth * percent, 0, 17)
    end)```
honest jolt
#

anyways the problem is that when plr resets the ui is deleted

#

disable remove on respawn

#

or idk the name of the property

#

u can find it in gui properties

gaunt quest
#

Why ui is deleted when plr resets?

honest jolt
#

i just told you why

vapid kayakBOT
#

studio** You are now Level 2! **studio

honest jolt
#

because of the property

lilac osprey
gaunt quest
#

I understand that, but one more problem is why i cant run after i dead

vapid kayakBOT
#

studio** You are now Level 2! **studio

honest jolt
#

i dont know; where even is your script?

gaunt quest
#

Up

honest jolt
#

great

#

up

#

🎈
🏠

orchid jay
#

nahhh

#

jit trippin

honest jolt
#

u deal with it new

orchid jay
#

alr

#

nahh i tried it and it worked even if the player died

gaunt quest
#

You didnt fix anything?

orchid jay
#

yea i didnt change anything

#

try doing it again

#

there might be en error on the gui names

gaunt quest
#

Ok

#

I think it may be because of other scripts

orchid jay
#

yea

vapid sage
#

you get the character once at the start of the game

#

this script is probably in starterplayerscripts

#

put it in startercharscterscripts

uncut belfry
#

q

gaunt quest
#

does the script work every time when the character is added when i put it in the Startercharacterscripts?

vapid sage
#

yes