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

How can I get a button to detect if the player has a game pass?

Hello, I am making a tycoon, and I am currently trying to get a game pass working. The game pass, if the player has it should allow the player to step on a button and get a 10% chance to have a VIP block spawn on the droppers every time the droppers spawn a part, My issue, is that my script isn't working properly.

script:

local gamePassId = 445136135
local passService = game:GetService("MarketplaceService")

 function vip(player)
        if passService:PlayerOwnsAsset(player, gamePassId)  then
            print(player.Name .. " has the game pass!")
            script.Parent.Parent.Parent.VIP.Value = "true"
        else
            print(player.Name .. " doesn't have the game pass...")
        end
    end

vipbutton = script.Parent.Head
vipbutton.Touched:connect(vip)

This script was provided as an answer to one of my previous questions. If I step on it in the "Studio Run" phase, I get an error on line "5": error:

01:13:38.925 - MarketplaceService:PlayerOwnsAsset() player should be of type Player, but is of type Part

The only idea I could get from this is to make the button used to call this script only accept player interaction, I'm not sure what this would fix but just a hunch. I wouldn't know how to do this though. I tried the other method for getting a game pass detected, but when I stepped on the button I got an error saying invalid player. I figured it was because I was running it in the studio, but when I tried it on a ROBLOX SERVER, the button faded as it's supposed to, but the VIP.Value was not set to "true".

So how could I get the button to properly detect that the player has a game pass and to change the VIP.Value to set equal to "true" so that the ability will be enabled on my map when ever a dropper checks for it?

Any insight would be appreciated, I'm at a dead end with my noobish abilities.

Thanks in advance!

In case you needed to see: scripts associated. Clicker Dropper script:

wait(2)
workspace:WaitForChild("PartStorage")

deb = true 
script.Parent.Clicker.ClickDetector.MouseClick:connect(function(wat)
		local vipblock = math.random(1,10)
		local luckyblock = math.random(1,100)
			if luckyblock == 1 and deb == true then
			deb = false
			 local part = game.ReplicatedStorage.luckyhyperbit:Clone()
			part.Parent = game.Workspace
			print("luckyblock")
			part.Name = "luckyhyperbit"
			local cash = Instance.new("IntValue",part)
			cash.Name = "Cash"
			cash.Value = 15 -- How much the drops are worth
			part.CFrame = script.Parent.Drop.CFrame - Vector3.new(0,1.3,0)
			part.FormFactor = "Custom"
			part.Size=Vector3.new(1.5, 1.5, 1.5) -- Size of the drops
			part.TopSurface = "Smooth"
			part.BottomSurface = "Smooth"
			game.Debris:AddItem(part,20) -- How long until the drops expire
			wait(.15)
			deb = true
			elseif luckyblock ~= 1 then
				
		if script.Parent.Parent.Parent.VIP.Value == "true" and deb == true and vipblock == 1 then
			deb = false
			 local part = game.ReplicatedStorage.viphyperbit:Clone()
			part.Parent = game.Workspace
			part.BrickColor = BrickColor.Random()
			print("vipblock")
			part.Name = "viphyperbit"
			local cash = Instance.new("IntValue",part)
			cash.Name = "Cash"
			cash.Value = 10 -- How much the drops are worth
			part.CFrame = script.Parent.Drop.CFrame - Vector3.new(0,1.3,0)
			part.FormFactor = "Custom"
			part.Size=Vector3.new(1, 1, 1) -- Size of the drops
			part.TopSurface = "Smooth"
			part.BottomSurface = "Smooth"
			game.Debris:AddItem(part,9) -- How long until the drops expire
			wait(.15)
			deb = true
		else
			
			deb = false
			local part = Instance.new("Part",workspace.PartStorage)
			part.BrickColor=script.Parent.Parent.Parent.DropColor.Value
			part.Material=script.Parent.Parent.Parent.MaterialValue.Value
			local cash = Instance.new("IntValue",part)
			cash.Name = "Cash"
			cash.Value = 1 -- How much the drops are worth
			part.CFrame = script.Parent.Drop.CFrame - Vector3.new(0,1.3,0)
			part.FormFactor = "Custom"
			part.Size=Vector3.new(1, 1, 1) -- Size of the drops
			part.TopSurface = "Smooth"
			part.BottomSurface = "Smooth"
			game.Debris:AddItem(part,20) -- How long until the drops expire
			wait(.15)
			deb = true
			end
		end
end)

player join script, using other game pass detection method.

local gamePassId = 445136135
 
game.Players.PlayerAdded:connect(function(player)
if game:GetService("GamePassService"):PlayerHasPass(player, gamePassId) then
    print(player.Name .. " has the game pass!")
else
    print(player.Name .. " doesn't have the game pass...")
end

end)

I don't know what else would need to be seen.

1 answer

In the first script, when the player touch the vipbutton, the script will detect only the part of the player, like an arm or a leg.

vipbutton.Touched:connect(part)

This line will detect a part of the Player's character. The part should be called "part".

function vip(PlayerPart)

When the function is called by the :connect then, the part (that we named "part") will be called PlayerPart in the function.

But this is not the Player. So we must find it with the function :GetPlayerFromCharacter()

Add the following line in your script:

local Player = game.Players:GetPlayerFromCharacter(PlayerPart.Parent)

Why PlayerPart.Parent? Because every part of the player's character is in a model.

local gamePassId = 445136135
local passService = game:GetService("MarketplaceService")

function vip(PlayerPart)
        local Player = game.Players:GetPlayerFromCharacter(PlayerPart.Parent)
        if passService:PlayerOwnsAsset(Player, gamePassId)  then
            print(Player.Name .. " has the game pass!")
            script.Parent.Parent.Parent.VIP.Value = "true"
        else
            print(Player.Name .. " doesn't have the game pass...")
        end
    end

vipbutton = script.Parent.Head
vipbutton.Touched:connect(part)

2 comments

0

Why would you have connect call "part"? That isn't defiened in this script whats so ever. Other than that it looks good haha.

0

Thanks for the script reguardless, I just changed the button back to call the vip function and added your additoins, thanks a ton!

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