Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there a way to make a touch part that gives points, but 2x the amount with a gamepass?

Asked by
0uico 20
2 years ago

So far this is my script for the part. It works just fine but I'm trying to add a 2x points gamepass.

local part = script.Parent
local canGet = true

local function onTouch(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
    if humanoid then
        local player = game.Players:FindFirstChild(otherPart.Parent.Name)
        if player and canGet then
            canGet = false
            player.leaderstats.Points.Value = player.leaderstats.Points.Value + 30
            wait(60) -- Cooldown between each point increase
            canGet = true
        end
    end
end

part.Touched:Connect(onTouch)

2 answers

Log in to vote
0
Answered by 2 years ago

You can use MarketplaceService:UserOwnsGamePassAsync(), which returns a bool depending on if the user owns the game pass. You can use that bool to determine whether to give 30 or 60 points.

By the way, I recommend using += so you do not have to type the path all over again.

player.leaderstats.Points.Value += 30

Also, you can remove the Humanoid check as it is unnecessary.

0
Hi thanks for helping, I tried using OwnsGamepassAsync but it still seems like it doesnt want to work. Probally just my bad scripting but yeah. 0uico 20 — 2y
Ad
Log in to vote
0
Answered by
0uico 20
2 years ago

My script looked like this by the way.

local part = script.Parent
local canGet = true
local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamepassAsnyc(player.UserId, 15971605) -- Gamepass Id

local function onTouch(otherPart)
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    if player and canGet then
    if ownsGamepass then 
            canGet = false
            player.leaderstats.Points.Value += 60
            wait(60) -- Cooldown between each point increase
            canGet = true
        end
    else
        canGet = false
        player.leaderstats.Points.Value += 30
        wait(60) -- Cooldown between each point increase
        canGet = true
    end
end

part.Touched:Connect(onTouch)
0
Is this a server script or client script? It seems like you are using Players.LocalPlayer and editing leaderstats. COUNTYL1MITS 312 — 2y
0
It's a client script. So far I manged to get it to double the points but the cooldown no longer works. 0uico 20 — 2y

Answer this question