- What do you want to achieve?
When the Player joins, the game checks if Player has a gamepass. If Player has gamepass, it gives them the radio.
- What is the issue?
Players.PlayerAdded isn’t working/doesn’t fire when I start my game.
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("RadioEvent")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local Radio = RadioSongGui.Radio
local RadioBrick = workspace.Folder.RadioGamePassBrick
local GamepassID = 24358592
local function GiveRadio(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local newRadio = Radio:Clone()
newRadio.Parent = Character
newRadio.CFrame = Character.Torso.CFrame * CFrame.Angles(0, math.pi, 0)
local weld = Instance.new("Weld")
weld.Part0 = newRadio
weld.Part1 = Character.Torso
weld.C0 = newRadio.CFrame:inverse()
weld.C1 = Character.Torso.CFrame:inverse()
weld.Parent = newRadio
Event:FireClient(Player)
end
local function OwnsGamepass(Player, Gamepass_ID)
return MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepass_ID)
end
local function CheckIfOwnsGamepass(Player)
print("TESTING")
Player.CharacterAdded:Connect(function(character)
if OwnsGamepass(character, GamepassID) then
GiveRadio(character)
end
end)
end
local function GamepassPurchased(Player, PurchasedGamepassID, PurchasedValue)
if PurchasedValue then
if PurchasedGamepassID == GamepassID then
GiveRadio(Player)
end
end
end
Players.PlayerAdded:Connect(CheckIfOwnsGamepass)
RadioBrick.Touched:Connect(PromptPurchase)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(GamepassPurchased)