hello all, I am trying to make my own stamina module for my games in the future, and im running into a few problems. number one I get an error right away because “passed value is not not” which I have marked as being an error below. I believe it is because of the parentheses next to the function call which fire it before the player is in, which I tried to fix with a few if statements, but I know that doesn’t stop the error from happening. The only problem is I don’t know how to pass the parameter of “player” without the parentheses. I have had this problem before, I would love to know a work around or if im doing something completely wrong. Also I know a lot of this script is probably very wrong but I haven’t even been able to test it because it breaks before I even get to that point.
local staminaScript = {}
local Players = game:GetService("Players")
local maxStamina = 100
local takeStamina = 25
local recoverStamina = 1
local maxRecovery = 5
local function recoveryLoop(player)
if player then
if player.recoveryTimer.Value > 0 then
repeat
player.recoveryTimer.Value -= 1
wait(1)
until player.recoveryTimer.Value == 0
player:WaitForChild("recovering").Value = false
end
end
end
local function takeStamina(player)
if player then
player.stamina.Value -= takeStamina
print(player.stamina.Value)
player.recovering = true
player.recoveryTimer = maxRecovery
recoveryLoop(player)
end
end
local function recoverStamina(player)
if player then
while wait(.1) do
if player.recovering then return end
player.Stamina.Value += recoverStamina
end
end
end
local function playerJumped(player, active)
if player and active then
player.recovering = true
takeStamina(player)
end
end
local function func(player)
local stamina = Instance.new("IntValue")
stamina.Value = maxStamina
stamina.Name = "Stamina"
stamina.Parent = player
local recoveryTimer = Instance.new("IntValue")
recoveryTimer.Value = 5
recoveryTimer.Name = "recoveryTimer"
recoveryTimer.Parent = player
local recovering = Instance.new("BoolValue")
recovering.Value = true
recovering.Name = "recovering"
recovering.Parent = player
recoverStamina(player)
recoveryLoop(player)
local char = player.Character or player.CharacterAdded:Wait()
-- passed value is not a function? VVVVVV
char:WaitForChild("Humanoid").Jumping:Connect(playerJumped(player))
--^^^^^^^^^^^^^^^^^^^^^
end
Players.PlayerAdded:Connect(func)
return staminaScript