Hello ![]()
Im honest i literly thinking im losing my mind here in this script i had the problem that it keeps rising in speed instead of staying one value and i thought that when it calculates
SpeedWalk = BaseWalk * SprintData.SpeedIncreaseDecrease
SpeedRun = BaseSprint * SprintData.SpeedIncreaseDecrease
that the value or result stays like example 3 and it only changes when a server event fires waht it currently dosent because no buffs are getting aplied or stun and when it sets it it should constently sets it to 3 but for some reson it increases indefenetly until im the flash and im at a loss currently having no idea why it isnt working can some one explain if i got it wrong or somthing and when yes help me with it
thank you ![]()
local Cas = game:GetService("ContextActionService")
local RNS = game:GetService("RunService")
local StaminaEvent = game.ReplicatedStorage.RemoteEvents.StaminaRemover
local GotStunned = game.ReplicatedStorage.RemoteEvents.GotStunned
local UpdateStats = game.ReplicatedStorage.RemoteEvents.UpdateStats
local SprintData = require(script.Parent:WaitForChild("CharacterStats"))-- Your module script here
local isStunned = false
local BaseWalk = SprintData.BaseWalkSpeed
local BaseSprint = SprintData.SprintSpeed
local SpeedWalk
local SpeedRun
SpeedWalk = BaseWalk * SprintData.SpeedIncreaseDecrease
SpeedRun = BaseSprint * SprintData.SpeedIncreaseDecrease
local hasToRecharge = false
local function clampStamina()
SprintData.Stamina = math.clamp(SprintData.Stamina, 0, SprintData.MaxStamina)
end
StaminaEvent.OnClientEvent:Connect(function(newStamina)
print("Stamina updated:", newStamina)
hasToRecharge = true
SprintData.Stamina -= newStamina -- update local value or UI bar
clampStamina()
end)
UpdateStats.OnClientEvent:Connect(function(newStats)
for key, value in pairs(newStats) do
SprintData[key] = value
end
SpeedWalk = BaseWalk * SprintData.SpeedIncreaseDecrease
SpeedRun = BaseSprint * SprintData.SpeedIncreaseDecrease
end)
local staminausage = 0.2
local stamianrecharg = 0.25
local rechargeTime = 0.25
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local RootPart = char:WaitForChild("HumanoidRootPart")
local RunSound = RootPart:WaitForChild("Running")
local sprint = script.RunAnim
local Runanim = humanoid.Animator:LoadAnimation(sprint)
local lastSprint = math.huge
local isSprinting = false
humanoid.JumpPower = 40
local jumpCooldown = 1
local canJump = true
GotStunned.OnClientEvent:Connect(function(duration)
isStunned = true
isSprinting = false
local oldBaseWalk = SprintData.BaseWalkSpeed
local oldSprint = SprintData.SprintSpeed
-- Prevent movement
SprintData.BaseWalkSpeed = 0
SprintData.SprintSpeed = 0
humanoid.WalkSpeed = 0
Runanim:Stop()
task.delay(duration, function()
isStunned = false
SprintData.BaseWalkSpeed = oldBaseWalk
SprintData.SprintSpeed = oldSprint
humanoid.WalkSpeed = oldBaseWalk * SprintData.SpeedIncreaseDecrease
end)
end)
humanoid.StateChanged:Connect(function(_, newstate)
if newstate == Enum.HumanoidStateType.Jumping and canJump then
isSprinting = false
Runanim:Stop()
humanoid.WalkSpeed = SpeedWalk
RunSound.PlaybackSpeed = 1
canJump = false
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
task.delay(jumpCooldown, function()
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
canJump = true
end)
end
end)
local function sprint(actionname, inputstate, inputtyp)
if isStunned then
return
end
print("SprintSpeed:", SprintData.SprintSpeed, "Multiplier:", SprintData.SpeedIncreaseDecrease)
if inputstate == Enum.UserInputState.Begin then
isSprinting = true
elseif inputstate == Enum.UserInputState.End then
isSprinting = false
end
if isSprinting then
humanoid.WalkSpeed = SpeedRun
RunSound.PlaybackSpeed = 1.25
if humanoid.MoveDirection.Magnitude > 0 then
Runanim:Play()
end
else
humanoid.WalkSpeed = SpeedWalk
RunSound.PlaybackSpeed = 1
Runanim:Stop()
end
end
Cas:BindAction("Sprint", sprint, true, Enum.KeyCode.LeftShift)
RNS.Heartbeat:Connect(function(delta)
local stamina = SprintData.Stamina
if not isSprinting then
humanoid.WalkSpeed = SpeedWalk
else
-- If sprinting, apply SprintSpeed with SpeedIncreaseDecrease
humanoid.WalkSpeed = SpeedRun
end
if stamina < staminausage then
isSprinting = false
RunSound.PlaybackSpeed = 1
Runanim:Stop()
humanoid.WalkSpeed = SpeedWalk
end
if isSprinting and humanoid.MoveDirection.Magnitude > 0 then
SprintData.Stamina = stamina - staminausage -- Reduce stamina using the module
lastSprint = tick()
else
if tick() - lastSprint >= rechargeTime and SprintData.Stamina < SprintData.MaxStamina or hasToRecharge == true then
SprintData.Stamina = SprintData.Stamina + stamianrecharg
clampStamina()
if SprintData.Stamina >= SprintData.MaxStamina then
hasToRecharge = false
end
end
end
end)
Note do to another script that literly shoots the event it resets it and prevents infenetly incresments proving that if the SpeedIncreaseDecrease is 1 insted of any other value like now 1.1(10% increase) it works all fine im not joking it works fine with no buff but when it gets one it breaks logic and like i set the reset makes it weird like you randomly speed up and slow down exept i trun the script off then i get indefenetly fast but it seems like it cause its because of the Chraachter script or the buff that this charachter ahs waht is movment speed if any debuff or buff apears it dosent do it