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

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

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

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.

1 comment

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.

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)

2 comments

0

Is this a server script or client script? It seems like you are using Players.LocalPlayer and editing leaderstats.

0

It's a client script. So far I manged to get it to double the points but the cooldown no longer works.

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