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

Trouble with gamepasses and giving tools..?

Asked by
shayner32 478 Trusted Moderation Voter
9 years ago

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

Log in to vote
3
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

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)

0
How would I end up cloning a tool from Lighting to their backpack, if they own the asset? shayner32 478 — 9y
0
In a localscript, of course. And where would I put the localscript? Starterpack? shayner32 478 — 9y
0
added an example, and starterpack, startergui, playerscripts are all possible places you can out it (accept answer if satisfied please n htank you) ImageLabel 1541 — 9y
0
It still requires they rejoin. shayner32 478 — 9y
Ad

Answer this question