Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i make this gamepass script work for speed and jump?

local script:

local speed = 6451920
game.Players.PlayerAdded:Connect(function(player)
local bought = game:GetService("MarketplaceService")
		if bought:UserOwnsGamePassAsync(player.UserId,speed) then
	print(player.Name.." got the gamepass")
	game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  for i = 1,16 do
   game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 60
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 100
  end
 end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  for i = 1,16 do
   game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
  end
 end
end)
		else
			print("dont got it")
		end
end)

i get no output or anything from this so im guessing i need to do it in a server script but the server script cant see into the local player all the time

1 comment

0

Ur stupid

1 answer

✓ Accepted answer

The problem is that the local script is executed after the player is added, therefor, PlayerAdded will not fire for you.

Luckily, you won't need to listen to PlayerAdded at all in your local script. Instead, when the user presses 'Left Shift', just check if that Player has the Gamepass, then change their walkspeed/jumppower accordingly.

local bought = game:GetService("MarketplaceService")

local speed = 6451920

--when we BEGIN pressing LeftShift
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
	if input.KeyCode == Enum.KeyCode.LeftShift then --when we press Left Shift, then
		if bought:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, speed) then --code block to check if the player has the GamePass!
			--if they bought the gamepass, then
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 60 --change our walkspeed
			game.Players.LocalPlayer.Character.Humanoid.JumpPower = 100 --change our movespeed
		end
	end
end)

--when we END pressing LeftShift
game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
	if input.KeyCode == Enum.KeyCode.LeftShift then --when we press Left Shift, then
		if bought:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, speed) then --code block to check if the player has the GamePass!
			--if they bought the gamepass, then
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 --change our walkspeed
			game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50 --change our movespeed
		end
	end
end)

I tried to preserve your code as best as possible. In Roblox, local scripts already know that the Local Player exists (they won't work without it), so you don't need to wait for it with PlayerAdded (I think that's where you are confused?)

3 comments

0

ye thanks completely forgot that

0

worked

0

after a bit of edit it worked, btw i didnt use ur script

This discussion is preserved as it was. New answers, comments, and votes are closed.