#sprint system bugging with humanoid on reset

1 messages · Page 1 of 1 (latest)

eager schooner
#

first top half of the script:

#

bottom of the script:

#

in the bottom of the script, i have a function where it checks if the player is sprinting, even when they are not moving but holding the sprintbutton but still sprints after walking

#

but everytime i reset, the gui never seems to function anymore, and the player isnt movign signal always prints that out on reset, even when i walk in roblox when testing

#

may someone please give me tips or any sort of help please

eager schooner
# eager schooner

this is where my module script, and gui, and localscript is at (the local script gets the playermodule, and the gui parents to playergui. it actually doesnt stay in startergui)

dark sparrow
#

can you show the PlayerStatusScript too please

#

also in ur code you are doing:
1.handling input
2.handling gui
3.handling health
4.handling player movement

makes it very very very messy if I were you id decouple the logic a bit

just send the local script and ill try make some suggestions

#

and also you are creating thr tween outside any function so it only gets created when you require the player module

eager schooner
#
local rs = game:GetService("ReplicatedStorage")
local playermodule = require(rs:WaitForChild("modules").PlayerModule)
local remotefunction = rs:WaitForChild("RemoteFunction")

remotefunction.OnClientInvoke = function(localPlayer, humanoid)
    
    if humanoid then
        print("Ddddddddddd")
    end
    
end

playermodule.SetPlayerStatus()

i started using remote funcs

#

but i kept coming across it can be only called from server or localscript even though i invoked it in my module script

dark sparrow
#

why are you using remote functions?

eager schooner
#

because everytime i reset it stops using the gui completely and it keeps printing out the fact that the player isnt moving anymore so i deicded to use humanoid.died then fire a remote

dark sparrow
# eager schooner because everytime i reset it stops using the gui completely and it keeps printin...

im gonna be honest I dont really understand this. Your local script is inside StartCharacterScripts so when the player dies and their character gets respawned the code will run. You require the playermodule and that creates the tween then you run setplayerstatus in the module which you then create a runservice connection.

So my theory is that when you die the heartbeat connection isnt being cleaned up so when ou die and respawn it keeps creating new heartbeat connections.

eager schooner
#

i think your theory may be right

#

i swear theres like

#

a disconnect rbxsingal for runservice?

dark sparrow
#

you should keep it simple you dont really need runservice for this

dark sparrow
eager schooner
#

and not only that

#

but like

#

my hp shows up in multiple numbers like 75.00000102001208e103 when its healing

#

but i heard math.floor is good for assisting with big numbers

#

like keeping them as digitd

#

s

eager schooner
#

okay

eager schooner
#

i dont even bother fiddling with math in roblox

#

so idrk

#

yeah i done it anyway

#

dw

#

math.floor

dark sparrow
# eager schooner how though

if I were you id just keep it simple and ditch the tween for now and make sure its working. When ur cahracter respawns set the gui stamina bar to the value you have in the module. Then while the shift key is pressed just make it so it decrements the stamina value and you update the stamina gui.

eager schooner
#

btw

dark sparrow
eager schooner
dark sparrow
eager schooner
#

ill be honest i hate tweens

dark sparrow
#

yea stamina systems are pretty complicated so I am skipping out on a LOT here but its fine

dark sparrow
#

cframe is lowkey worse I hate that

eager schooner
#

when u know what ur doing with stamina bars then u get the point

eager schooner
#

and i cant even call :Disconnect

#

i justget an error and it doesnt show in the list (if ykwim)

#

bro wtf

dark sparrow
#

give it a variable name like local conn = runservice.Heartbeat:Connection then just do conn:Disconnect()

eager schooner
#

oh

#

well i was close enough i believe

dark sparrow
#

yea

eager schooner
#

heartbeat = runservice.Heartbeat:Connect()?

dark sparrow
#

yea just do like local conn = whatever

#

also humanoid.healthchanged and humanoid.died etc are connections that also need cleaning up

eager schooner
#

yeah u mentionened earlier that my code was really messy

#

me personally i think its alright in my eyes

#

but i assume you have a longer experience with coding

#

so you can point out the problems

#

not saying that as if im demandimg it like your my servant

dark sparrow
dark sparrow
#

yea so just try to clean those connections and see if you still got an error

eager schooner
#

including the health

eager schooner
dark sparrow
dark sparrow
#

they are different types of connections

eager schooner
#

i just realised that when u said that

#

ok so ive got the runservice fixed up now (looked at a forum)

dark sparrow
#

well I think they still keep it when they die my bad actually

#

just paste the SetPlayerStatus() function so I can just edit it rq

eager schooner
#
function playermodule.SetPlayerStatus()
    
    humanoid.Died:Connect(function()
        charactermovementphysicssimulation:Disconnect()
    end)
    
    healthtext.Text = humanoid.Health -- this sets the humanoids health, which is that the humanoid's is already at 100
    
    if humanoid then -- all the functions run inside this if statement
        print("Humanoid found!, the humanoid's health is currently at: "..humanoid.Health)
        
        humanoid.HealthChanged:Connect(function(health)
            print("The health has been changed, Health is now at: "..health)
            healthtext.Text = math.floor(health)
        end)
        
        charactermovementphysicssimulation = runservice.Heartbeat:Connect(function()
            local currentstate = humanoid:GetState()
            local movedirmag = humanoid.MoveDirection.Magnitude
            
            if currentstate == Enum.HumanoidStateType.Running and movedirmag > 0 then
                print("Is walking")
                
                if isSprinting then
                    humanoid.WalkSpeed = SprintSpeed
                    sprintbarTween:Play()    
                    StaminaValue -= 1
                    print("Player is sprinting")
                    print(StaminaValue)
                else
                    humanoid.WalkSpeed = NormalWalkingSpeed
                end
                
                if StaminaValue <= 0 then
                    --isSprinting = false
                    humanoid.Health = 0
                    print("Player run out of available stamina")
                end
                
            else
                print("player isnt moving")
                sprintbarTween:Pause()
                humanoid.WalkSpeed = NormalWalkingSpeed
            end    
        end)
        return playermodule.ControlsUpdated()
    end
    
    warn("No humanoid found.")
    return nil
    
end

#

i was doing smth before i was abt to edit the humanoid func

#

i was debugging rq

dark sparrow
#

ok 2 secundos

eager schooner
#

ok

dark sparrow
#
function playermodule.SetPlayerStatus()
    
    local humanoidDiedConn
    local humanoidHealthChangedConn
    local runserviceConn
    
    humanoidHealthChangedConn = humanoid.HealthChanged:Connect(function(health)
        print("The health has been changed, Health is now at: "..health)
        healthtext.Text = math.floor(health)
    end)

    runserviceConn = runservice.Heartbeat:Connect(function()
        local currentstate = humanoid:GetState()
        local movedirmag = humanoid.MoveDirection.Magnitude

        if currentstate == Enum.HumanoidStateType.Running and movedirmag > 0 then
            print("Is walking")

            if isSprinting then
                humanoid.WalkSpeed = SprintSpeed
                sprintbarTween:Play()    
                StaminaValue -= 1
                print("Player is sprinting")
                print(StaminaValue)
            else
                humanoid.WalkSpeed = NormalWalkingSpeed
            end

            if StaminaValue <= 0 then
                humanoid.Health = 0
                print("Player run out of available stamina")
            end

        else
            print("player isnt moving")
            sprintbarTween:Pause()
            humanoid.WalkSpeed = NormalWalkingSpeed
        end    
    end)
    
    humanoidDiedConn = humanoid.Died:Connect(function()
        humanoidHealthChangedConn:Disconnect()
        runserviceConn:Disconnect()
        humanoidDiedConn:Disconnect()
    end)
    
    return playermodule.ControlsUpdated()
end
#

this is a really bad way of doing it but for this small project its fine

#

see if this works

eager schooner
#

do i just copy that whole script

dark sparrow
#

yea should be fine

eager schooner
#

also bro u didnt have to do it for me dawg you couldve told me

dark sparrow
eager schooner
#

like i greatly appreciate you for doing it but like your pushing urself

#

like usually ill just get told what to do but youre different

dark sparrow
eager schooner
#

take that as a complement

eager schooner
dark sparrow
#

could be wayyyyyyyyyyyyyyyyy cleaner but its fine for now just get comfortable using the roblox services then you can worry about formatting ur code

eager schooner
#

describe how it can be way cleaner bro im curious

#

what u just coded i think thats the most minimalistic simple code for this situation rn

#

u dont have to

dark sparrow
# eager schooner describe how it can be way cleaner bro im curious

1.you are handling the stamina logic on the client cheaters can set the stamina value to whatever they want and have inf stamina (this isnt that big of a problem since if they are cheating they can already go fast but you should still be aware since its more serious for other stuff like player data).
2.you have input,stamina,hp,gui all in one script you should split them up since the more advanced ur logic becomes the harder it will become to maintain.
3.if you want to add effects while running or adding other activies to ur game then you will have to check fi they are running to make sure they arent conflicting with anything else (you can use a finite state machine to fix this preferably a hierarchal finite state machine).

theres probs a bunch of other stuff too but these are the main ones really

#

you'll catch on the longer you script it just comes with experience

eager schooner
#

yeah

eager schooner
dark sparrow
#

dont worry about all that for now just get the script working and worry about that stuff later

eager schooner
#

ok, i was just about to try and change input into like an input system (for the future for like keybinds and stuff)

dark sparrow
eager schooner
#

ill be honest im still stuck on making the module work for the ui

#

not 4 the ui

#

when the player resets

#

idk if u told me the solution to try for it
if u did then i probably forgot

#

it prints na when the plr resets

#

(my localscript is in startercharscripts)

dark sparrow
#

lowkey might be easier if u just invite me to the game so I can fix it its probs something really small and easy to miss

eager schooner
#

whats ur user

#

for collaboration

dark sparrow
#

Rowdy_Monkey

eager schooner
#

oke

#

very classic name and simple

#

u must be an og rolobx user

dark sparrow
#

nah not really

eager schooner
#

oh

#

fe

#

u have to be a connection to edit

dark sparrow
#

whats ur user

#

ea

eager schooner
#

xxgames1024xx

dark sparrow
#

did u send request?

eager schooner
#

i have now

dark sparrow
#

oh yea I see w avatar haha

#

yea you should be able to share it with me now

eager schooner
eager schooner
#

r u in the studio?

dark sparrow
#

ye

#

lemme reopen it maybe it ahsnt loaded in

eager schooner
#

oke

tall ginkgo
#

yo

dark sparrow
#

whatst he game called I cant seem to see it

tall ginkgo
#

whatb yall making

dark sparrow
#

oh just tryna help them with a stamina ui bug

tall ginkgo
#

k

eager schooner
dark sparrow
#

ohh lemme see

#

oh im in ok ill see the problem sorry I thought it was a left over game lol

eager schooner
#

dw about it bro

dark sparrow
#

ok im just gonna change the script up just a bit

#

lowlkey might be easier to just write it from scratch ill just rename ur orignal module so it doesnt get lost

eager schooner
#

oke

dark sparrow
#

yea its working now

#

I had to change some of the gui also since you were using scale instead of offset

#

you can probs make the code more modular I just wanted to make sure it works

eager schooner
#

did u do all of it in one script?

#

also thank you

#

ill be honest not using tween is way better

#

and to be honest i get why it works not and why it werent before

#

now

dark sparrow
dark sparrow
#

but you can probs take it from there goodluck!

#

also just be mindful of gui since using offset can make the gui appear different on peoples screens

eager schooner