Hello. I’ve been recently trying to make a +1 jump every second game and I’m trying to implement a gamepass to where if the player has a certain gamepass, it will multiply the jump power by 2 every second. However, it’s not working and I’m not sure why.
EX: If the player is getting 4 jumppower per second, and if they buy the gamepass, they will get 8 per second instead of 4.
Code:
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("Data")
local startingJump = 0
local function saveData(player)
local data = {player.leaderstats.Jump.Value, player.leaderstats.Wins.Value}
datastore:SetAsync(player.UserId, data)
end
local function loadData(player)
local playerData = datastore:GetAsync(player.UserId) or {0, 0}
local ls = Instance.new("Folder", player)
ls.Name = "leaderstats"
local jump = Instance.new("IntValue", ls)
jump.Name = "Jump"
jump.Value = playerData[1]
local wins = Instance.new("IntValue", ls)
wins.Value = playerData[2]
wins.Name = "Wins"
ls.Parent = player
end
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
game.Players.PlayerAdded:Connect(loadData)
function handleWinPad(winpad)
local onDebounce = {}
winpad.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not onDebounce[player] then
onDebounce[player] = true
player:LoadCharacter()
player.leaderstats.Jump.Value = startingJump
player.leaderstats.Wins.Value += tonumber(winpad.Name) or 1
task.wait(5)
onDebounce[player] = nil
end
end)
end
for _, winpad in pairs(workspace:WaitForChild("WinPads"):GetChildren()) do
handleWinPad(winpad)
end
while task.wait(1) do
for _, player in pairs(game.Players:GetPlayers()) do
local playerLS = player:WaitForChild("leaderstats")
playerLS.Jump.Value += (1 + playerLS.Wins.Value)
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.JumpHeight = playerLS.Jump.Value
end
end
end
local MarketplaceService = game:GetService("MarketplaceService")
local passId = 171530446
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId) then
player.leaderstats.Jump.Value *= 2
end
end)
Would appreciate some help as I’ve been trying to get this to work for a while and I’m not sure why. Thanks!
Oh right, that’s my bad. You can use Attributes for the player. Here’s a code snippet of an example using MarketPlaceService:
-- services
local marketPlaceService: MarketplaceService = game:GetService("MarketplaceService")
-- variables
local gamePassId: number = 0000000
-- functions
if (marketPlaceService:UserOwnsGamePassAsync(0000, gamePassId)) then
player:SetAttriute("OwnsDoubleJumpGamepass", true)
end
If the player owns the gamepass, it gives an Attribute named ‘OwnsDoubleJumpGamepass’ to the player. This is a sort of global value so every script knows the player owns the gamepass. Anyway, within your increment function, you can use another if statement to tell if the player owns the gamepass, as such:
if (player:GetAttribute("OwnsDoubleJumpGamepass")) then
playerLS.Jump.Value += (1 + playerLS.Wins.Value) * 2
else
playerLS.Jump.Value += (1 + playerLS.Wins.Value)
end
This should give the player double the amount of what they would originally receive. Hope this helps
Do you mind if you could show what the code would look like if you put those 2 chunks inside of the script? Trying to figure out where to place those within the script included in the original post. I assume it’s probably somewhere near the end though because it needs to get playerLS in order for the script to work properly.
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("Data")
local startingJump = 0
local function saveData(player)
local data = {player.leaderstats.Jump.Value, player.leaderstats.Wins.Value}
datastore:SetAsync(player.UserId, data)
end
local function loadData(player)
local playerData = datastore:GetAsync(player.UserId) or {0, 0}
local ls = Instance.new("Folder", player)
ls.Name = "leaderstats"
local jump = Instance.new("IntValue", ls)
jump.Name = "Jump"
jump.Value = playerData[1]
local wins = Instance.new("IntValue", ls)
wins.Value = playerData[2]
wins.Name = "Wins"
ls.Parent = player
end
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
game.Players.PlayerAdded:Connect(loadData)
function handleWinPad(winpad)
local onDebounce = {}
winpad.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not onDebounce[player] then
onDebounce[player] = true
player:LoadCharacter()
player.leaderstats.Jump.Value = startingJump
player.leaderstats.Wins.Value += tonumber(winpad.Name) or 1
task.wait(5)
onDebounce[player] = nil
end
end)
end
for _, winpad in pairs(workspace:WaitForChild("WinPads"):GetChildren()) do
handleWinPad(winpad)
end
local MarketplaceService = game:GetService("MarketplaceService")
local passId = 171530446
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId) then
player:SetAttriute("OwnsDoubleJumpGamepass", true)
end
end)
while task.wait(1) do
for _, player in pairs(game.Players:GetPlayers()) do
local playerLS = player:WaitForChild("leaderstats")
if (player:GetAttribute("OwnsDoubleJumpGamepass")) then
playerLS.Jump.Value += (1 + playerLS.Wins.Value) * 2
else
playerLS.Jump.Value += (1 + playerLS.Wins.Value)
end
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.JumpHeight = playerLS.Jump.Value
end
end
end
while task.wait(1) do
for _, player in pairs(game.Players:GetPlayers()) do
local playerLS = player:WaitForChild("leaderstats")
task.spawn(function()
if (player:GetAttribute("OwnsDoubleJumpGamepass")) then
playerLS.Jump.Value += (1 + playerLS.Wins.Value) * 2
else
playerLS.Jump.Value += (1 + playerLS.Wins.Value)
end
end)
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.JumpHeight = playerLS.Jump.Value
end
end
end
task.spawn(function()
while task.wait(1) do
for _, player in pairs(game.Players:GetPlayers()) do
local playerLS = player:WaitForChild("leaderstats")
if (player:GetAttribute("OwnsDoubleJumpGamepass")) then
playerLS.Jump.Value += (1 + playerLS.Wins.Value) * 2
else
playerLS.Jump.Value += (1 + playerLS.Wins.Value)
end
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.JumpHeight = playerLS.Jump.Value
end
end
end
end)