Shift to run game pass

I have a shift to run game pass in my game. The game pass works and all but every time I use my mouse to click (turn my camera) the run stops working. robloxapp-20210428-2019285.wmv (2.5 MB)

3 Likes

Kindly provide the script here. We can help after seeing it.

2 Likes

local Player = game.Players.LocalPlayer
local MPS = game:GetService(“MarketplaceService”)
local UIS = game:GetService(“UserInputService”)
local Character = Player.Character or Player.CharacterAdded:Wait()

local GamepassID = 17279284 --Gamepass ID here

print(“Script running”)
UIS.InputBegan:Connect(function(Input, Chatted)
print(“Firing”)
if Chatted then
return
end

if Input.KeyCode == Enum.KeyCode.LeftShift and MPS:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
	print("Sprinting")
	Character.Humanoid.WalkSpeed = 30
else
	print("Not the correct key or the player doesn't have the gamepass")
	Character.Humanoid.WalkSpeed = 16
end

end)

UIS.InputEnded:Connect(function(Input, Chatted)
if Chatted then
return
end

if Input.KeyCode == Enum.KeyCode.LeftShift then
	print("Resting")
	Character.Humanoid.WalkSpeed = 16
end

end)

1 Like

I have no clue why it put it like that.

1 Like
local Player = game.Players.LocalPlayer
local MPS = game:GetService(“MarketplaceService”)
local UIS = game:GetService(“UserInputService”)
local Character = Player.Character or Player.CharacterAdded:Wait()

local GamepassID = 17279284 --Gamepass ID here
local GamepassOwned = MPS:UserOwnsGamePassAsync(Player.UserId, GamepassID)

print(“Script running”)
UIS.InputBegan:Connect(function(Input, Chatted)
print(“Firing”)
if Chatted then
return
end

if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and GamepassOwned then
	print("Sprinting")
	Character.Humanoid.WalkSpeed = 30
else
	Character.Humanoid.WalkSpeed = 16
end
end)

Let me know if this fixes your issue, otherwise we can connect it to RenderStepped.

1 Like

Hmmmmmmmmm, that did not work.

1 Like

im pretty new to studio so i have no clue what RenderStepped is

1 Like

dont worry about it, i will make shift to run available to everyone

1 Like
local Player = game.Players.LocalPlayer
local MPS = game:GetService("MarketplaceService")
local UIS = game:GetService("UserInputService")
local Character = Player.Character or Player.CharacterAdded:Wait()

local GamepassID = 17279284 --Gamepass ID here
local GamepassOwned = MPS:UserOwnsGamePassAsync(Player.UserId, GamepassID)

print("Script running")
game:GetService("RunService").RenderStepped:Connect(function()

   if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and GamepassOwned then
	   Character.Humanoid.WalkSpeed = 30
   else
	   Character.Humanoid.WalkSpeed = 16
   end
end)

This, in theory, should work.

Edit: I checked. It works. Here’s a video. (BTW, change the unicode quotes.

robloxapp-20210429-1004447.wmv (958.5 KB)

2 Likes

Does it print anything? Or no output is seen?

1 Like

I suggest making it a local script, make a normal shift to run script, verify it works, then make it a character or player starter script whatever you want, check if the player owns the gamepass if they do not then use script:Destroy()

This will need to be a script within the player otherwise it won’t work.
Also do not check if they own the gamepass every time the player presses shift as that will not be an instant run.

1 Like

The reason the run stops workung is because you added the else statement on the InputBegan event. This means whenever you click a mouse or keybind you will stop sprinting even though your finger is still on W. Remove the

else
print(“Not the correct key or the player dosen’t have the gamepass”)
Character.Humanoid.WalkSpeed = 16

2 Likes

Woohoo! It works! Thank you very much!

2 Likes

Ohhhhh, thank you for letting me know!

1 Like

If that helped you, kindly mark it as the solution, as it helps other who stumble upon the same problem to find the answer swiftly and in a hassle-free way.

1 Like

I did lol, thanks again really appreciate it!

2 Likes

RenderStepped basically is a loop that runs every time the Frame is in the middle of running (or something similar, can’t remember off the top of my head). RunService.PreRender, RunService.RenderStepped, etc. are useful for loops and especially when you want to set a custom camera system, as you’ll most likely have to constantly update the camera.

2 Likes