So,i wanted to add some low stamina effects to a sprint script i got from a tutorial,but for some reason it just doesn’t do anything though it reacts to the stamina being bigger than 50 and lower than 50,first i tried it with the blur,then after it didn’t work i thought that lighting effects just don’t work on localscripts, i tried adding a sound and it still didn’t work
Here’s the local script: (The low stamina effect thing is at the bottom)
local UserInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local ContextActionService = game:GetService("ContextActionService")
local Player = game.Players.LocalPlayer
local HeavyBreathing = Instance.new("Sound")
HeavyBreathing.Name = "LowStam"
HeavyBreathing.SoundId = "rbxassetid://180315285"
HeavyBreathing.Parent = script.Parent
HeavyBreathing.Looped = true
HeavyBreathing.PlaybackSpeed = 1.5
local Info = TweenInfo.new(0.3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
local char = Players.LocalPlayer.Character
local debounce = nil
local Goals1 = {FieldOfView = 70}
local Goals2 = {FieldOfView = 80}
local function Run(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then print("Started")
if debounce ~= true then
debounce = true
replicatedStorage.Sprint:FireServer("Began")
TweenService:Create(workspace.Camera,Info,Goals2):Play()
task.wait(5)
debounce = false
end
end
if userInputState == Enum.UserInputState.End then print("Ended")
replicatedStorage.Sprint:FireServer("Ended")
TweenService:Create(workspace.Camera,Info,Goals1):Play()
end
end
ContextActionService:BindAction("Running",Run,true,Enum.KeyCode.LeftShift)
-- Doesnt Work
replicatedStorage.UpdateStam.OnClientEvent:Connect(function(stamina,maxStamina)
print("GotTheEvent") -- Prints
if stamina < 50 then
HeavyBreathing:Play()
print("Stamina < 50") -- Prints
elseif stamina > 50 then
if HeavyBreathing.Playing == true then
HeavyBreathing:Stop()
end
print("Stamina > 50") -- Prints
end
end)
-- Doesnt Work
And the serverscript
local replicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local runService = game:GetService("RunService")
local maxStamina = 500
local staminaRegen = 1
local SprintSpeed = 27
local sprintStaminaCost = 2
local sprintingPlayers = {}
Players.PlayerAdded:Connect(function(player)
local stamina = Instance.new("IntValue",player)
stamina.Value = maxStamina
stamina.Name = "Stamina"
stamina.Changed:Connect(function(property)
replicatedStorage.UpdateStam:FireClient(player,stamina.Value,maxStamina)
end)
end)
replicatedStorage.Death.OnServerEvent:Connect(function(player)
local humanoid = player.Character.Humanoid
humanoid.WalkSpeed = sprintingPlayers[player.Name]
sprintingPlayers[player.Name] = nil
end)
replicatedStorage.Sprint.OnServerEvent:Connect(function(player,state)
local humanoid = player.Character.Humanoid
if state == "Began" and humanoid.MoveDirection.Magnitude > 0 then
sprintingPlayers[player.Name] = humanoid.WalkSpeed
humanoid.WalkSpeed = SprintSpeed
elseif state == "Ended" and sprintingPlayers[player.Name] then
humanoid.WalkSpeed = sprintingPlayers[player.Name]
sprintingPlayers[player.Name] = nil
end
end)
runService.Heartbeat:Connect(function()
for index,player in pairs(Players:GetChildren()) do
local stamina = player.Stamina
local name = player.Name
if not sprintingPlayers[name] then -- if not in the sprinting players table
if stamina.Value > maxStamina then
stamina.Value = maxStamina
elseif stamina.Value < maxStamina then
stamina.Value += staminaRegen
end
else
if stamina.Value >= sprintStaminaCost then
stamina.Value -= sprintStaminaCost
else
player.Character.Humanoid.WalkSpeed = sprintingPlayers[name]
sprintingPlayers[name] = nil
end
end
end
end)
How can i make it do stuff when the stamina is low?
Thanks in advance.