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

Trouble with gamepasses and giving tools..?

Hey there. I recently made a donation script, if you donate you'll get a gun. Unfortunately, you have to wait for a new server to actually receive the gun. So, I attempted to make a script that when your purchase is verified, it creates a boolvalue in workspace with that person's name. I got that done, but I'm having trouble making it so that if there's a boolvalue with someone's name, it will give a weapon to that person when they respawn.

This is the code I have so far [making the values is already sorted out]

players = game.Players:GetChildren()

function givetools()
	base = script.Parent:GetChildren()
		for i, base 
end

1 answer

PlayerHasPass

You were more than likely using PlayerHasPass with the GamePassService. PlayerHasPass caches results after the first call, which is usually when the player enters the server. If the player purchases anything after than first check, it will still return that previously cached value, which is (false).

PlayerOwnsAsset

PlayerOwnsAsset, when used in LocalScripts, will return live results from the ROBLOX website. Therefore, no matter when he purchases the item, it will return the most recently updated value.

PlayerOwnsAsset (player, assetId)

local Market = game:GetService('MarketplaceService')
local Storage = game:GetService('ReplicatedStorage')
-- Set storage to the repository containing the weapon
local Player = game:GetService('Players').LocalPlayer
local Asset = 12345


local function donated(player, assetId)
	if Market:PlayerOwnsAsset(player, assetId) then
	    for i, weapon in pairs(Storage:GetChildren()) do
	        if weapon.Name == "NameofWeapon" then
	            -- Name weapon to give
	            weapon:clone().Parent = Player.BackPack
	        end
	    end
	end
end


donated(Player, Asset)

4 comments

0

How would I end up cloning a tool from Lighting to their backpack, if they own the asset?

0

In a localscript, of course. And where would I put the localscript? Starterpack?

0

added an example, and starterpack, startergui, playerscripts are all possible places you can out it (accept answer if satisfied please n htank you)

0

It still requires they rejoin.

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