How to Improve Run System (Mobile + PC)

So, I am wanting to improve this Script which finalizes the Players Speed and Animation. Another key factor is that for Mobile there’d be a “RunBind”. I also need the Mobile RunBind to enhance with the Stamina System so that the game can comprehend properly to its extent.

Here is the Kit for the Run & Stamina System:
System.rbxm (10.6 KB)

3 Likes

Perhaps you should move your post to CodeReview section. Cause you are not having issues with the code right? you are just looking for optimization?

1 Like

I am trying to make that the “RunBind” for the Run System Script in StarterCharacter works with the Stamina dread.

Because when I hold Shift to Run the Stamina will work but when I hold the “RunBind” on Mobile testing service the Stamina doesn’t comprehend with the Stamina System.

Can you please provide code???

@GulgPlayer I have sent the Kit for the Run & Stamina System

Ok, but I logged in from phone, so I would appreciate if you gave me your code instead of model.

Well you see, I could only give the Run System because the Stamina System contains more than just the one Script.

Run System:

-- Player Run System Script
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")

local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = "rbxassetid://15411322421"
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
	if InputState == Enum.UserInputState.Begin and BindName == "RunBind" then
		Running = true
		Humanoid.WalkSpeed = 25
	elseif InputState == Enum.UserInputState.End and BindName == "RunBind" then
		Running = false
		if RAnimation.IsPlaying then
			RAnimation:Stop()
		end
		Humanoid.WalkSpeed = 10
	end
end

Humanoid.Running:connect(function(Speed)
	if Speed >= 10 and Running and not RAnimation.IsPlaying then
		RAnimation:Play()
		Humanoid.WalkSpeed = 25
	elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 10
	elseif Speed < 10 and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 10
	end
end)

Humanoid.Changed:connect(function()
	if Humanoid.Jump and RAnimation.IsPlaying then
		RAnimation:Stop()
	end
end)

game:GetService("ContextActionService"):BindAction("RunBind", Handler, true, Enum.KeyCode.LeftShift)
game:GetService("ContextActionService"):SetImage("RunBind", "rbxassetid://9525535512")
1 Like

@GulgPlayer here’s the Script it’s for the RS - Run System

I’d recommend you to learn about Mobile Input here and how to make a mobile button in-experience here.

It’s good that you’re using ContextActionService in your code, the tutorial i have given also uses this service.

.

Well, you see I am trying to make the Run System enhance with the Stamina System so when the Player would to interact with the “RunBind” the Stamina will reduce just like when it does for “Shift to Run”.

You’ve mentioned about Mobile addition, uhhh, yes, you can make an stamina system.

What exactly you need in stamina system?

If you would to go to very top of the post I’ve added a Kit File.

@ZxCryB
Maybe if possible do you think you could compromise the Run System Script into the Stamina Handler Script so then it will work in a total function, as in the comparison from having two Scripts defying the Players Movement & Speed. I need the “RunBind” to comprehend to the exact extent in its way of interacting with the “RunBind” so it can have the same affect with the Stamina System. Does that make sense or not?

In other words, try and make the Run System Script fit into place with the Stamina Script (Handler).