Hi I have been trying to make a stamina bar script
I have 2 main issues
1.) How should I go about subtracting stamina from the players current stamina in the server script
dont mind the current method that has “while max stamina”
2.)Also how do I make the local script change the gui in my local script I used udim.2 new
sorry for the mess first time asking for help on the dev forum. I am also willing to take feedback on how to properly use the devforum thank you in advance
Local script down here
local userInput = game:GetService('UserInputService')
local Player = game:GetService('Players')
local replicatedStorage = game:GetService("ReplicatedStorage")
local sprintSpeed = 50
local walkSpeed = 16
local player = Player.LocalPlayer
local function BeginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
print("start")
replicatedStorage.RemoteEvents.Sprint:FireServer("Began")
end
end
end
end
local function EndSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
print("stop")
replicatedStorage.RemoteEvents.Sprint:FireServer("Ended")
end
end
end
end
userInput.InputBegan:Connect(BeginSprint)
userInput.InputEnded:Connect(EndSprint)
replicatedStorage.RemoteEvents.StaminaUpdate.OnEvent:Connect(function(stamina, maxStamina)
Player.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new(0,(stamina/maxStamina)*.2, 0, 29)
end)
serverscript
local replicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local runService = game:GetService("RunService")
local sprintSpeed = 50
local walkSpeed = 16
local maxStamina = 500
local sprintingPlayer = {}
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)
replicatedStorage.RemoteEvents.Sprint.OnServerEvent:Connect(function(player, state)
print("hello")
local humanoid = player.Character.Humanoid
if state == "Began" then
humanoid.WalkSpeed = sprintSpeed
while maxStamina > 0 do
maxStamina = maxStamina -1
end
print("com")
print(maxStamina)
elseif state == "Ended" then
humanoid.WalkSpeed = walkSpeed
print("bust")
end
end)