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

My script still makes a GUI visible when the player DOESN'T own a gamepass! Why?!?!

I have this code which makes a GUI visible when a player owns a GUI. Does anyone know a way to make this code more, reliable?

Likewise, people who own it sometimes still see the [BUY NOW] button instead!

passid = 256633733

local GamePassService = game:GetService("GamePassService")
function respawned(char)
local player = game.Players:FindFirstChild(char.Name)

if GamePassService:PlayerHasPass(player, passid) then
script.Parent.Parent.Spawn.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Parent.OwnedBikes.Bike12.Visible = true
end
end

game.Workspace.ChildAdded:connect(respawned)

Cheers,

Michael

This is the Hierarchy of the script. The Red arrow is where this code is located.

4 comments

0

can you provide the hierarchy please?

0

Edited question!

0

are you doing it on studio or on a roblox server?

0

Roblox server.

3 answers

✓ Accepted answer

Please try this:

--// Initialization

local GamePassService = game:GetService("GamePassService")

--// Variables

gamepass1 = 256633733

--// Functions

function onCharacterSpawn(character)
  local player = game.Players:GetPlayerFromCharacter(character)
  
  if GamePassService:PlayerHasPass(player, gamepass1) then
    script.Parent.Parent.Spawn.Visible = true
    script.Parent.Visible = false
    script.Parent.Parent.Parent.OwnedBikes.Bike12.Visible = true
  end
end

--// Triggers

game.Workspace.ChildAdded:connect(onCharacterSpawn)

5 comments

0

Will do so now!

0

It looks like it worked fine! :D Cheers.

0

For the record, your issue was with "game.Players:FindFirstChild(char.Name)". This is not the correct method, always use GetPlayerFromCharacter! I look forward to seeing your game!

0

Still people can get all the bikes ;-;

passid = 256633733

local GamePassService = game:GetService("GamePassService")
function respawned(char)
local player = game.Players:FindFirstChild(char.Name)

if GamePassService:PlayerHasPass(player, passid) then
script.Parent.Parent.Spawn.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Parent.OwnedBikes.Bike12.Visible = true
else
end
end

game.Workspace.ChildAdded:connect(respawned)

Adding an else will tell the script that if something doesn't happen or has happened, etc, do this. So if OwnedBikes.Bike12.Visible = false then it will remove.

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