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)
Kindly provide the script here. We can help after seeing it.
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)
I have no clue why it put it like that.
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
.
Hmmmmmmmmm, that did not work.
im pretty new to studio so i have no clue what RenderStepped is
dont worry about it, i will make shift to run available to everyone
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)
Does it print anything? Or no output is seen?
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.
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
Woohoo! It works! Thank you very much!
Ohhhhh, thank you for letting me know!
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.
I did lol, thanks again really appreciate it!
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.