I have a sprinting script and that worked fine. until I tried to add a game pass that makes you walk 2x faster. when you buy the game pass you walk 2x faster until you click shift then it changes back to normal walk speed. can anyone help? I want it to be when you have the game pass and you click shift and release shift that it goes back to 2x speed (40) instead of going to normal speed (16).
script:
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = game.Workspace.CurrentCamera
local SpeedBoost = 25 -- What your speed is going to be when you hold shift
local DefaultSpeed = 16 -- What your speed is going to be when you let of shift
local UserInputService = game:GetService("UserInputService")
local GamepassSpeedBoost = 40
UserInputService.InputBegan:Connect(function(key) --When player holds shift key, run code
if key.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = SpeedBoost
Camera.FieldOfView = Camera.FieldOfView
end
end)
local MarketPlaceService = game:GetService("MarketPlaceService ")
local PlayerBoughtThisGamePass = MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)
if PlayerBoughtThisGamePass then
UserInputService.InputEnded:Connect(function(key)-- When player lets go of shift key, run code
if key.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = GamepassSpeedBoost
Camera.FieldOfView = Camera.FieldOfView
if not UserInputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = DefaultSpeed
Camera.FieldOfView = Camera.FieldOfView
end
end)

1 comment
If you properly indent your code. You'll recognize all the syntax errors present.