Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's wrong with my staminabar script? The bar won't tween?

Asked by 6 years ago

(Note: game is filtered enabled) (Note: I'm getting an error saying I can't compare a number with user data) (Note: the stamina bar isn't tweening in size)

LOCALSCRIPT INSIDE THE GUI

-- Variables
local replicatedStorage = game:GetService("ReplicatedStorage")
local sprintEvent = replicatedStorage:WaitForChild("sprintEvent")
local sprintEnded = replicatedStorage:WaitForChild("sprintEnded")
local userInput = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local humanoid = plr.Character:WaitForChild("Humanoid")
local staminaFolder = plr:WaitForChild("stamFolder")
local stamina = staminaFolder:WaitForChild("stamina")
local staminaBar = script.Parent.background.staminabar
local staminaGui = script.Parent
local isSprinting = false
local canSprint = true


-- Scripting
userInput.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        isSprinting = true
        sprintEvent:FireServer()
        while isSprinting and stamina.Value > 0 do
            staminaBar:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), "Out", "Sine", .5)
            stamina.Value = stamina.Value - 1
            wait(.2)
        end
        if humanoid.WalkSpeed == 16 then
            isSprinting = false
        end
    end
end)


userInput.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        isSprinting = false
        sprintEnded:FireServer()
        while isSprinting and stamina.Value < 100 do
            stamina.Value = stamina.Value + 1
            staminaBar:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), "Out", "Sine", .5)

        end
        if stamina.Value >= 33 then
            canSprint = true
        elseif stamina.Value == 0 then
            canSprint = false
        end
    end
end)


SCRIPT INSIDE SERVERSCRIPTSTORAGE


-- Scripting game.Players.PlayerAdded:Connect(function(player) local stamFolder = Instance.new("Folder", player) stamFolder.Name = "stamFolder" local stamina = Instance.new("IntValue", stamFolder) stamina.Name = "stamina" stamina.Value = 100 end)

Here's a photo of the hierarchy, https://i.imgur.com/a80eGgE.png

0
You said there's an error. What's the line of the error? DragonOfWar900 397 — 6y
0
He said the output said, "can't compare number with user data" which I provided why that would happen. He tried to use a string 'user data' where a Enum 'number' would be needed. Impacthills 223 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

With the TweenSize function you need to use the Enum data types Roblox provides. Instead of your function call looking like this:

staminaBar:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), "Out", "Sine", .5)

It should look like this:

staminaBar:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .5)
Ad

Answer this question