So i did a sprint script a little by myself and a little assisted by a youtube video. I made it work and all that stuff but whenever i sprint, the sprint GUI bar goes invisible, even tho the property Visible is true , the position is still the same and the size is all the same.
I am a beginner scripter so please explain if i did something wrong or if there is an issue at the placements.
Anyway here are the placements and the scripts
The placement of each script, event and GUI
StaminaServer script located in ServerScriptService
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local maxStamina = 500
local staminaRegen = 2
local sprintModifier = 1.8
local sprintStaminaCost = 5
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.RemoteEvents.StaminaUpdate:FireClient(player, stamina.Value, maxStamina)
end)
end)
-- Sprint key pressed or released
replicatedStorage.RemoteEvents.Sprint.OnServerEvent:Connect(function(player, state)
local humanoid = player.Character.Humanoid
if state == "Began" and humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and humanoid.MoveDirection.Magnitude > 0 then
sprintingPlayers[player.Name] = humanoid.WalkSpeed
humanoid.WalkSpeed = humanoid.WalkSpeed * sprintModifier
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 stamina.Value > maxStamina then
stamina.Value = maxStamina
elseif stamina.Value < maxStamina then
stamina.Value = stamina.Value + staminaRegen
end
else
if stamina.Value >= sprintStaminaCost then
stamina.Value = stamina.Value - sprintStaminaCost
else
player.Character.Humanoid.WalkSpeed = sprintingPlayers[name]
sprintingPlayers[name] = nil
end
end
end
end)
StaminaClient script located in Starter Player > StarterCharacterScripts
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
-- Sprint Key Pressed
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
replicatedStorage.RemoteEvents.Sprint:FireServer("Began")
end
end)
-- Sprint Key Released
userInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
replicatedStorage.RemoteEvents.Sprint:FireServer("Ended")
end
end)
-- Update Stamina GUI
replicatedStorage.RemoteEvents.StaminaUpdate.OnClientEvent:Connect(function(stamina, maxStamina)
players.LocalPlayer.PlayerGui.StatusBars.StatusMainFrame.StaminaMainFrame.StaminaBar.Size = UDim2.new((stamina / maxStamina) * .2, 0, .044, 0)
end)
If there are any more info you want , tell me in the replies. Thank you for helping me <3