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

I think this code is suppose to enable a ScreenGui, but it's not working! Can someone help?

Asked by 6 years ago

I have a piece of code, and it SHOULD enable a screengui whenever a player has a gamepass, but it's not working! Can someone please help? Code:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 4439769  -- Change this to your game pass ID 

function onPlayerSpawned(player) 

    local hasPass = false

    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
        print("Has Game Pass")
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end

    if hasPass == true then
        game.Players.LocalPlayer.PlayerGui.Test.Enabled = true
    end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerSpawned:Connect(onPlayerSpawned)
0
Anyting on output(F9) Leamir 3138 — 6y
0
Yeah, Its saying Playerspawned is not a member of Player, and it's saying 'Serverscriptservice.Script' line 34 SBlankthorn 329 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

If you have FE enabled, then the script will not work because the server cannot change properties of the gui.

Also the event should be this

Players.PlayerAdded:Connect(onPlayerSpawned)
0
OMG THIS MADE IT WORK. THANK YOU SO SO SO MUCH. SBlankthorn 329 — 6y
Ad

Answer this question