So in my game I want to add a 2x money gamepass. I am pretty new to scripting and I wasn’t sure how to include it in my already written code. So I watched a yt vid and it was rlly good, but I wasn’t sure how to add this into the already existing code. Here are the 2 different lines(First one is from the yt tutorial and second is from the game)
local function giveMoney(player)
player.leaderstats.Money.Value += (1 + player:FindFirstChild(“2xMoney”).Value)
There is more to the script but thats all that is important I think.
Ok and here is what im using to let players sell their sap for money:
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player:WaitForChild(“leaderstats”)
local money = leaderstats:FindFirstChild(“Money”)
local Sap = leaderstats:FindFirstChild(“Sap”)
if Sap.Value > 0 then
money.Value = money.Value + Sap.Value
Sap.Value = “0”
end
end
end)
Thank you in advance! If you wanna know anything about how things are referenced in other scripts or something, lmk.
local doublePass = false
function checkPass()
--- check for gamepass
--- if true, set doublePass = true
end checkPass()
script.Parent.Touched:Connect(function(hit)
---
local pay = Sap.Value
if doublePass then pay *= 2 end
money.Value += pay
---
How I would do it is, I would when you need to give some money I would check if they own the gamepass through the usage of UserOwnsGamePassAsync which is part of the marketplaceservice and then if they own the game pass just give them double the amount of money but if they don’t then just give them the normal amount.
On the top of my head I cannot remember if the UserOwnsGamePassAsync has any rate limit so you may need to just check when the user joins the server and then set that as a bool value or something like that if it does have a rate limit.
This might work, didn’t test anything here. (non-local script)
local MarketPlaceService = game:GetService("MarketplaceService")
local doublePass, gamepassID = false, 12345678 -- your gamepass id
function Spawned(player)
local HasGamepass = false
local success, message = pcall(function()
HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
end)
task.wait(1)
if not success then
warn("Checking Gamepass "..tostring(message))
return
else
doublePass = true
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
task.wait(3) Spawned(player)
end)
end)
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local money = leaderstats:FindFirstChild("Money")
local Sap = leaderstats:FindFirstChild("Sap")
if Sap.Value > 0 then
local pay = Sap.Value
if doublePass then pay *= 2 end
money.Value += pay
Sap.Value = 0
end
end
end)
Trying not to hammer the server here. I take it the touched function is not possible within 4 seconds of a respawn or login. Script may need some love. Also tried to use as much of what you had as possible.
Tbh, I dont feel like learning how to screen record and stuff on mac its not a very good system. So ill just tell you if thats alr. So basically, you collect sap from trees and go to the shop to sell the sap. I want a 2x money gamepass so when you sell the sap, it will give you 2x the money you would normally get.
Then that’s what you have the way it was from my post.
If you’re selling others things this is not to effect then you can’t use the same way for everything.