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

How can I fix my Gamepass script, for changing the color of a brick?

Ive been working on a game for a little while, and im decently new to scripting. I seem to be getting an error and im not sure why. Apparently it cant find the value of player. Am I doing something wrong? local gamepass = script:WaitForChild("GamePassid")

local service = game:GetService("GamePassService")

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

if service:PlayerHasPass(player,gamepass.Value)then

local Part = Workspace.Part

Part.Color = BrickColor.new("Bright red")

end

1 comment

0

try using the player's User Id. "if service:PlayerHasPass(player.UserId,gamepass.Value) then

2 answers

✓ Accepted answer

Hello Joshuadr737. There are a few apparent issues I see in your code. The main one being your method is deprecated! Lets begin. I'm going to provide a new and more clear way to show you how everything should be formatted. Here we go:

Setup

  1. Create a Script in ServerScriptService
    • Name it "GamePassCheck"
  2. Make a part in workspace
    • Name it "GamepassOwnedPart"

Script Making

GamePassCheck:

MPS = game:GetService("MarketPlaceService")
GamePassID = --Put the game pass ID here
Indicator = workspace:WaitForChild("GamepassOwnedPart")

game.Players.PlayerAdded:Connect(function(plr)
    local plrID = plr.UserId
    if MPS:UserOwnsGamePassAsync(plrID,GamePassID) then
	    Indicator.BrickColor = BrickColor.new("Really Red")
	end
end)

Script Context

In the game pass check script, we first detect when a new player is joining. From there, we get the players unique ID, and check if they own the gamepass with that ID. If they do, we change the bricks color to red. With any further questions/comments/concerns, please feel free to reply to my post or comment! ~mc3334

2 comments

0

It worked pretty good, had a few errors but I fixed em up. I ended up using local MarketplaceService = game:GetService("MarketplaceService") Spasiba for the reply, it helped alot. (Mainly because I have no experience in gamepasses)

0

np

mc3334 helped me out alot, ended up tweaking it a tiny bit. but it works fine now.

local MarketplaceService = game:GetService("MarketplaceService") GamePassID = --gamepassid Indicator = workspace:WaitForChild("GamepassOwnedPart")

game.Players.PlayerAdded:Connect(function(plr) local plrID = plr.UserId if MarketplaceService:UserOwnsGamePassAsync(plrID,GamePassID) then Indicator.BrickColor = BrickColor.new("Really Red") end end)

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