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

I cant figure out how to make a gamepass script that gives you a tool. [Filtering Enabled]?

I'v tried a lot couldn't find anything on YouTube or anything from open sources that let me make a script like this. The point is that if a user owns a Gamepass the permanently get a tool, I'm not the best with FE scripting but I tired. Heres what I got

LocalScript (Located in startergear)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GamepassEvent = ReplicatedStorage:WaitForChild("GamepassEvent")
 
GamepassEvent:FireServer()

Script (ServerScriptStorage)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GamepassEvent = Instance.new('RemoteEvent', ReplicatedStorage)
GamepassEvent.Name = "GamepassEvent"

local function OnGamepassEventFired()
	local id = 4760037
 
game.Players.PlayerAdded:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
        game.ServerStorage["Tool"]:Clone().Parent = game.Players.LocalPlayer.StarterGear
    else
        print(player.Name .. " doesn't have the game pass...")
    end


end)
end

Any help will be greatly appreciated.

1 answer

###Things wrong with your code.

##1. You didn’t Connect your FireServer to an OnServerEvent

##2. You didn’t connect your PlayerAdded event properly

##3. You used GamePassService:PlayerHasPass() when it is broken

###Here is your code for the server side.

local id = 4760037
local marketplaceService = game:GetService"MarketplaceService"

GamepassEvent.OnServerEvent:Connect(function(player)
    if marketplaceService:UserOwnsGamePassAsync(player.UserId, id) then
        local tool = game:GetService("ServerStorage").Tool
        tool:Clone().Parent = player.Backpack
        tool:Clone().Parent = player.StarterGear
    else
        print"User doesn’t own pass"
    end
end)

###On a side note, switch to Connect, as ROBLOX may discontinue connect in the future. Also, don’t put your PlayerAdded event inside the function, instead connect a function to the event. But as you can see, we didn’t use PlayerAdded.

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