Stamina build up script breaks when trying to merge it with a gui

You can write your topic however you want, but you need to answer these questions:

  1. I want to make a stamina bar GUI and when I attempt to merge both of them in one script it breaks

This is my stamina script it builds up speed:


local UIS = game:GetService("UserInputService") 
local TS = game:GetService("TweenService") 
local plr = game.Players.LocalPlayer


UIS.InputBegan:Connect(function(key) -- 
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 23}):Play()
	end
end)

UIS.InputEnded:Connect(function(key) -- 
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
	end
end)
  1. Here is a screenshot of stamina GUI when I play the game it doesn’t moveimage

  2. I’ve tried to search up the solution on Youtube I also tried reading some articles on the Developer Hub but I had no luck

1 Like

Do you see any console errors when testing in studio?

1 Like

I tested and it works.
Where did you place this script?
You should place LocalScripts inside services like StarterGui, StarterPack or StarterPlayerScripts (StarterPlayerScripts is inside StarterPlayer).

2 Likes

the problem is that when I press shift my GUI, doesn’t work it stays the same, and the local script is inside the gui frame.
image

1 Like

Oh, then that script is completely unrelated since all it does it change the WalkSpeed.

2 Likes

Do you know any solutions on how to fix this problem?

1 Like

Well, there isn’t really any problem since the script works (works as in it does everything you wrote inside of it) but it just hasn’t been given any instructions to change the stamina bar in that script you showed.

What were the two scripts you merged?

1 Like

If you’re attempting to merge a server script & a local script then you won’t be able to, instead you’ll need to make use of RemoteEvents to allow for the client to communicate with the server and vice versa.

1 Like

I don’t think he even needs that. The script which he provided works in a local script and the GUI thingy can also be stored in that same script.

1 Like

He mentioned a second script which is yet to be shared, if it’s a local script too then he’ll be able to merge them fine.

1 Like

i tried attempting a script that I saw on YouTube
image

1 Like

He mentioned the GUI stamina script.

1 Like

Yes & what about the other script?

1 Like

Can you provide both scripts that you’re trying to merge? Would be useful, thanks.

1 Like

The other script is the one he posted here… That script is used so he can build up speed.

1 Like

I don’t see the 2nd script in the thread, can you link the post?

1 Like

image

local UIS = game:GetService("UserInputService") 
local TS = game:GetService("TweenService") 
local plr = game.Players.LocalPlayer


UIS.InputBegan:Connect(function(key) -- 
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 23}):Play()
	end
end)

UIS.InputEnded:Connect(function(key) -- 
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
	end
end)
1 Like

Can you copy and paste the 1st script like you did for the 2nd?

1 Like