How can I add anything to make this script work with a button gui?

local RunningSpeed = 20
local NormalSpeed = 10
local MaxStamina = 100

local StaminaDecrease = 0.4
local SprintKey = Enum.KeyCode.LeftShift

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Exterior = script.Parent.Exterior
local Bar = Exterior.Bar

local Sprinting = false
local StaminaAmount = MaxStamina 

UserInputService.InputBegan:Connect(function(Key, Processed)
	if not Processed then
		if Key.KeyCode == SprintKey then
			
			
			Sprinting = true
		end
	end
end)

UserInputService.InputEnded:Connect(function(Key, Processed)
	if not Processed then
		if Key.KeyCode == SprintKey then
			

			Sprinting = false
		end
	end
end)

I cant figure out how to make this script work with a moble button. I tried to make a sepreate script were it would run when the button clicked but i think i did somthing wrong. This is the original script how can I make it work?

You can maybe use a remote event that fires when the button is pressed?
For example: you can make a remote event in ReplicatedStorage, and make a function that when the GUI is clicked, it fires an event that will show your gui

Will it work for a run script with stamina or for a shop gui?

It should work for anything. Remote events are a way to make multiple scripts work for one.
Like I can make a remote event fire from a client script into a server script.

are you trying to make a toggle button or hold to run button?

Im trying to make a toggle button

local Sprinting = false
local Button = script.Parent -- the text button

Button.MouseButton1Click:Connect(function()
    Sprinting = not Sprinting 
    if Sprinting then
        -- Start running
    else
        -- Stop running
    end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.