#script doesnt work after my character dies
1 messages · Page 1 of 1 (latest)
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)
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
format it? what do you mean
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)```
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
Why ui is deleted when plr resets?
Oh i see
i just told you why
** You are now Level 2! **
because of the property
disable reset on respawn
I understand that, but one more problem is why i cant run after i dead
** You are now Level 2! **
i dont know; where even is your script?
Up
u deal with it new
You didnt fix anything?
yea i didnt change anything
try doing it again
there might be en error on the gui names
yea
you get the character once at the start of the game
this script is probably in starterplayerscripts
put it in startercharscterscripts
q
I see but can i ask what's the difference?
does the script work every time when the character is added when i put it in the Startercharacterscripts?
yes