#so im making a stamina run scirpt

1 messages · Page 1 of 1 (latest)

silver obsidian
#

im trying to make a stamina run scirpt but i dont know how to make a this part work i hope its my last error in my script

fervent surge
#

so

#

I do not see the whole script

#

but by the error I can assume that

#

you got a function and a boolean variable called the same

#

this makes the script confused making it think you are trying to call a variable as a function

#

and spits the error

#

however it would be really ok if I could see the whole script

#

@silver obsidian

silver obsidian
#

ok

fervent surge
#

just as I though

#

so, on the first picture you can see there is a variable called "sprint" which has the value false, right?

silver obsidian
#

yeah

fervent surge
#

and on the second image there is a function that is also called sprint

#

this makes the script confused

#

the way to fix this would be changing any of the names

#

I'd change the function name

#

Change the thing in red to other name

fervent surge
#

that should fix it

silver obsidian
#

nope unless im doing it wrong

peak zephyrBOT
#

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

fervent surge
#

can I see the script again?

#

and the output

#

to see if there is a new error

silver obsidian
#

same error

fervent surge
#

send me the whole script on a single message, copy paste it this way

#

so it gets sent with a block

peak zephyrBOT
#

studio** You are now Level 17! **studio

silver obsidian
#

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character =player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local pg = player.PlayerGui

local stamina = 100
local maxstamina = 100

local speed = 8
local drain = 20
local refresh = 10
local staminaregen = 0

local move = false
local sprinting = false
local tired = false

local function move(active)
if tired then return end

humanoid.walkspeed = active and humanoid.walkspeed + speed or humanoid.walkspeed - speed
sprinting = active

end

local function onInput(input)
if input.UserInputType == Enum.UserInputType.Gamepad1 or input.KeyCode ~= Enum.KeyCode.LeftShift then
move = input.userInputState == Enum.UserInputState.Begin
move(sprinting)
end

end

local function updateStaminaUi()
game["StarterGui"].energy.frame.staminabar.Size = UDim2.new(math.clamp(stamina / maxstamina, 0, 1), 0, 1, 0)
game["StarterGui"].energy.frame.percent.Text = tostring(math.floor(stamina)) .. "/" .. tostring(math.floor(maxstamina))
end

game.UserInputService.InputBegan:Connect(onInput)
game.UserInputService.InputEnded:connect(onInput)

game["Run Service"].Heartbeat:connect(function(DeltaTime)
if sprinting then
stamina = math.max(0, stamina - drain * DeltaTime)
updateStaminaUi()
print(math.floor(stamina))
if stamina == 0 then
move(false)
tired = true
end
else
stamina = math.min(100, stamina + refresh * DeltaTime)
if stamina >= staminaregen then
updateStaminaUi()
tired = false
print(math.floor(stamina))
if sprinting then
move(true)
end
end
end
end)

fervent surge
#

that also works I guess

silver obsidian
#

oh liek dm you personly

fervent surge
#

nono

#

chill

silver obsidian
#

huh?

fervent surge
#

can you send it like

#

a block

silver obsidian
#

how

fervent surge
#

with three of these symbols att he start of it and on the end of it`

silver obsidian
#
local rs = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character =player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local pg = player.PlayerGui

local stamina = 100
local maxstamina = 100

local speed = 8
local drain = 20
local refresh = 10
local staminaregen = 0

local move = false
local sprinting = false
local tired = false

local function move(active)
    if tired then return end
    
    humanoid.walkspeed = active and humanoid.walkspeed + speed or humanoid.walkspeed - speed
    sprinting = active
end

local function onInput(input)
    if input.UserInputType == Enum.UserInputType.Gamepad1 or input.KeyCode ~= Enum.KeyCode.LeftShift then
        move = input.userInputState == Enum.UserInputState.Begin
        move(sprinting)
    end
        
end

local function updateStaminaUi()
    game["StarterGui"].energy.frame.staminabar.Size = UDim2.new(math.clamp(stamina / maxstamina, 0, 1), 0, 1, 0)
    game["StarterGui"].energy.frame.percent.Text = tostring(math.floor(stamina)) .. "/" .. tostring(math.floor(maxstamina))
end

game.UserInputService.InputBegan:Connect(onInput)
game.UserInputService.InputEnded:connect(onInput)

game["Run Service"].Heartbeat:connect(function(DeltaTime)
    if sprinting then
        stamina = math.max(0, stamina - drain * DeltaTime)
        updateStaminaUi()
        print(math.floor(stamina))
        if stamina == 0 then
            move(false)
            tired = true
        end
    else
        stamina = math.min(100, stamina + refresh * DeltaTime)
        if stamina >= staminaregen then
            updateStaminaUi()
            tired = false
            print(math.floor(stamina))
            if sprinting then
                move(true)
            end
        end
    end
end)```
fervent surge
#

perfect

#

thanks

fervent surge
#

but on a different line

silver obsidian
#

no smae line

#

same*

fervent surge
#

this is because you have the same problem with other function

#

so

#

it says the error is at line 21

#

31*

#

in that line you call a move function

#

but above the script there is also a variable called move

#

it is the same mistake

#

the same solution

silver obsidian
#

so what do i name it then

fervent surge
silver obsidian
#

yeah i know

fervent surge
#

and replace every other place where you use the variablw

silver obsidian
#

what variable

fervent surge
#

the one at top

#

that is called move

#

you can change it to moving

#

or smt like that

#

btw this line

#

I think it is wrong

#

that syntax makes no sense

#

what are you trying to achieve in there

silver obsidian
#

oh

#

a user input

fervent surge
#

lets leave it like that for now and if it spits an error then we fix it

silver obsidian
#

um i changed it but its still giving me the same error

fervent surge
#

so, above that line exists the problematic line

#

that still makes a new variable called the same

#

is this variable and the one at top the same one?

#

like you're overwriting it?

silver obsidian
fervent surge
#

there, you see the mistake

#

that variable is named 'move'

silver obsidian
#

no

#

yeah

fervent surge
#

and the function is also named move

silver obsidian
#

no

fervent surge
#

you changed the function name?

silver obsidian
#

yeah

fervent surge
#

alright so

silver obsidian
#

same error

fervent surge
#

on this line also change the name

silver obsidian
#

witch one

fervent surge
#

the line where you call the moveing function

#

change move -> moveing

silver obsidian
#

welp thx but now i have aother error i might just start over

fervent surge
#

you do not name it walkspeed

#

it is WalkSpeed

#

change walkspeed -> WalkSpeed

#

capitalization is important

silver obsidian
#

oh okay hold

#

okay that worked but now ever whenevr i click something i stop moving and cant move after wards

fervent surge
#

I do not see any place where theres a click event

#

It is probably on another script

silver obsidian
#

ik

#

or jump i stop moving

#

idk

fervent surge
#

that is something with another script

silver obsidian
#

like what

#

oh

fervent surge
#

also on these lines change move() to moveing() also

#

any errors on output when you click or jump?

silver obsidian
#

yeah when i jumped i stoped moving

#

nope still stop even after repalcing it

#

shouldi send you the renewed version of the script

fervent surge
#

thats a problem with the movement system but I do not have that script

#

so I cannot help you with that

silver obsidian
#

okay thanks for your help i can atleast learn from this but now i got to scrap this witch is whatever cya man

fervent surge
#

alright