Why this script doesn't work?

Hello, I’ve tried to make a gamepass but my script doesn’t work and I don’t understand why, so I’ve tried to print the bool value to know if a player has bought the gamepass and it’s work perfectly until the character die :
ServerScriptService :

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local RemoteEvent = ReplicatedStorage.GamePass
local Players = game:GetService("Players")
local GamePass = 100274949

Players.PlayerAdded:Connect(function(Player)
	local HasBoughtGamePass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamePass)
	if HasBoughtGamePass then
		RemoteEvent:FireClient(Player)
	end
end)

StarterCharacterScript :

local UserInputService = game:GetService("UserInputService")
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.GamePass
local Players = game.Players
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local GamePass = 100274949
local CanDoubleJump = false
local HasDoubleJumped = false
local HasBoughtGamePass = false

RemoteEvent.OnClientEvent:Connect(function()
	HasBoughtGamePass = true
end)

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(Player, BoughtGamePass, Purchased)
	if BoughtGamePass == GamePass and Purchased then
		HasBoughtGamePass = true
	end
end)

Humanoid.StateChanged:Connect(function(Old, New)
	if Old == Enum.HumanoidStateType.Jumping and New == Enum.HumanoidStateType.Freefall then
		CanDoubleJump = true
	else
		CanDoubleJump = false
	end
end)

Humanoid.StateChanged:Connect(function(Old, New)
	if Old == Enum.HumanoidStateType.Freefall and New == Enum.HumanoidStateType.Landed then
		HasDoubleJumped = false
	end
end)

UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
	if CanDoubleJump and not HasDoubleJumped and HasBoughtGamePass then
		HasDoubleJumped = true
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
end)
2 Likes

What the gamepass should do? I don’t think I can help you, but I prefer to ask

2 Likes

The gamepass should make the player can jump two times !

1 Like

As I thought, I won’t be able to help you :laughing:

2 Likes

Thanks anyway :+1: !
Have a nice day !

2 Likes

Have a nice day too! I hope you’ll find how to do!

2 Likes

Please try to use that search tool up the top of the page. You should be able to debug the errors that this script gives you easily and fix the issue.

If you still cannot find a solution, there is nothing wrong with copy and pasting a gamepass script template and modifying it to suit your game :slight_smile:

1 Like