Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[UPDATE!] The output says that i need to close my function on line 32... ????????

I'm sorry for the inconvenience, I have released I had many spelling errors, and other errors. I've fixed those mistakes, though there is still a problem. It says that I need to close my function on line 32... I did..? Btw, I changed the localscript below.

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local players = game:GetService("Players")
local inputService = game:GetService("UserInputService")

local player = players.LocalPlayer 
local character = playerCharacter or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")

local stamina = 100

local Interface = {}
do
	local playerGui = player:WaitForChild("PlayerGui")
	
	local gui = playerGui:WaitForChild("Stamina")
	local frame = gui:WaitForChild("Frame")
	local textlabel = frame:WaitForChild("TextLabel")
	local bar = frame:WaitForChild("Percentage")
	
	local UDim2_new = UDim2.new
	
	function Interface:UpdateStamina()
		bar.Size = UDim2_new(stamina/100, 0, 0, 0)
		textLabel.Text = ("Stamina - 4d / 100")format(stamina)
	end
	
	
end


inputService.InputBegan:connect(function(input, event)
	if (event or stamina <= 0) then return end
	
	local key = input.KeyCode.Name
	print(key)
	
	if (key == "LeftControl") then
		humanoid.Walkspeed = 26
		repeat
			if (humanoid.MoveDirection.Magnitude > 0.1) then
			stamina = stamina - 1
			Interface:UpdateStamina()
			end
			wait(0)
		until not inputService:IsKeyDown(Enum.KeyCode.LeftControl) do
		
		humanoid.WalkSpeed = script.Parent.Parent.Humanoid.Walkspeed
		
		if (stamina <= 0) then
			wait(3)	
		else
			wait(1)
		end
		
		while (not inputService:isKeyDown(Enum.KeyCode.LeftControl)and stamina >= 100) do
			stamina = stamina + 0.1
			Interface:UpdateStamina()
			wait(0)
		end
	end
end

8 comments

0

Are you sure it's not line 6 where you have players:LocalPlayer instead of players.LocalPlayer?

0

uhh lemme see

0

oh, no when i replaced the : with . it gave me another error at line 46 where it has ))

0

You shouldn't do this on the client entirely because people can hack it. Update it on the client, manage the stamina on the server.

0

What is the actual error? 'output says there is something wrong with the 7th line' isn't very descriptive.

0

i dont know how to do that, and also the erorr is on line 7 it says, "Expected '(', '{' or got 'local'"

0

idk what to do when it does that

0

Added an answer based on the output.

1 answer

✓ Accepted answer

"Expected '(', '{' or got 'local'" says to me that it's a syntax error. I looked at the line before and spotted something that would confuse the heck out of lua.

You have a colon on line six, so lua thinks you're calling a method or something and is expecting a parameter or just ().

Replace the : with a . on line six and you'll be just fine!

EDIT:

Looking at your new problem, you should just add an end) to end the anonymous function at line 32.

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local players = game:GetService("Players")
local inputService = game:GetService("UserInputService")

local player = players.LocalPlayer 
local character = playerCharacter or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")

local stamina = 100

local Interface = {}
do
    local playerGui = player:WaitForChild("PlayerGui")

    local gui = playerGui:WaitForChild("Stamina")
    local frame = gui:WaitForChild("Frame")
    local textlabel = frame:WaitForChild("TextLabel")
    local bar = frame:WaitForChild("Percentage")

    local UDim2_new = UDim2.new

    function Interface:UpdateStamina()
        bar.Size = UDim2_new(stamina/100, 0, 0, 0)
        textLabel.Text = ("Stamina - 4d / 100")format(stamina)
    end


end


inputService.InputBegan:connect(function(input, event)
    if (event or stamina <= 0) then return end

    local key = input.KeyCode.Name
    print(key)

    if (key == "LeftControl") then
        humanoid.Walkspeed = 26
        repeat
            if (humanoid.MoveDirection.Magnitude > 0.1) then
            stamina = stamina - 1
            Interface:UpdateStamina()
            end
            wait(0)
        until not inputService:IsKeyDown(Enum.KeyCode.LeftControl) do

        humanoid.WalkSpeed = script.Parent.Parent.Humanoid.Walkspeed

        if (stamina <= 0) then
            wait(3) 
        else
            wait(1)
        end

        while (not inputService:isKeyDown(Enum.KeyCode.LeftControl)and stamina >= 100) do
            stamina = stamina + 0.1
            Interface:UpdateStamina()
            wait(0)
        end
    end
end
end)

2 comments

0

thanks!

0

Just add an 'end' and a ')' to close the anonymous function at line 32.

This discussion is preserved as it was. New answers, comments, and votes are closed.