#sprint system bugging with humanoid on reset
1 messages · Page 1 of 1 (latest)
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
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)
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
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
why are you using remote functions?
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
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.
i think your theory may be right
i swear theres like
a disconnect rbxsingal for runservice?
you should keep it simple you dont really need runservice for this
yea its just disconnect() I think
how though
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
yea just clamp it
okay
math.clamp?
i dont even bother fiddling with math in roblox
so idrk
yeah i done it anyway
dw
math.floor
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.
the tween is for the sprintbar
btw
yea just ditch it for now and add it later just make sure its working the tween just adds complexity
i did think about not using tween and only decreasing the stamina value, then updating the stamina bar gui by the incrementing sprint value
yea just do that when ur starting out to make sure the logic works then you can the tween later so like you can do:
1.stamina is at 100 you take away 10 from it.
2.stamina is now 90
3.you make a tween to make the stamina bar go from 100 percent to 90 percent.
etc...
ill be honest i hate tweens
yea stamina systems are pretty complicated so I am skipping out on a LOT here but its fine
eh they are not that bad once u get used to them
cframe is lowkey worse I hate that
theyre not tbh
when u know what ur doing with stamina bars then u get the point
oh yea
and i cant even call :Disconnect
i justget an error and it doesnt show in the list (if ykwim)
bro wtf
you cant call runservice:stop() you gotta stop the individual connection
give it a variable name like local conn = runservice.Heartbeat:Connection then just do conn:Disconnect()
yea
heartbeat = runservice.Heartbeat:Connect()?
yea just do like local conn = whatever
also humanoid.healthchanged and humanoid.died etc are connections that also need cleaning up
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
trust me ive written way worse code
yea no problem thats what the help forums are for
yea so just try to clean those connections and see if you still got an error
runservice connections?
including the health
fair enough
yea the runservice ones and the healthchanged ones
yeah
oke
they are different types of connections
i just realised that when u said that
ok so ive got the runservice fixed up now (looked at a forum)
that wont work since when the character dies they lose the reference to the humanoid (old character) plus you havent created the heartbeat connection so you are disconnecting nothing
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
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
ok 2 secundos
ok
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
do i just copy that whole script
yea should be fine
also bro u didnt have to do it for me dawg you couldve told me
eh its just easier if I do it really quick
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
this took like 2 mins its fine brahh
take that as a complement
yeah ill be honest this is way cleaner
could be wayyyyyyyyyyyyyyyyy cleaner but its fine for now just get comfortable using the roblox services then you can worry about formatting ur code
oke
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
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
yeah
fair enough, i read' all of that
dont worry about all that for now just get the script working and worry about that stuff later
ok, i was just about to try and change input into like an input system (for the future for like keybinds and stuff)
yea thats another thing I forgot to mention yea inputs are really annoying if you are gonna make a big game make sure you have a good input handler in place
yeah
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)
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
Rowdy_Monkey
so i can do this
oke
very classic name and simple
u must be an og rolobx user
nah not really
xxgames1024xx
did u send request?
i have now
thank you bro
ok
r u in the studio?
oke
yo
whatst he game called I cant seem to see it
whatb yall making
oh just tryna help them with a stamina ui bug
k
untitled experience
ohh lemme see
oh im in ok ill see the problem sorry I thought it was a left over game lol
dw about it bro
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
oke
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
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
yea it should be fine I think you can probs figure out how to make it more modular (splitting up gui and inputs)
you should still use tweens since right now it just goes down by 1 but for damage you might take 10 damage so you will have to tween from 100 hp to 90 hp
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
yeah fair enoguh
i will dont u worry