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!
01 | passid = 256633733 |
02 |
03 | local GamePassService = game:GetService( "GamePassService" ) |
04 | function respawned(char) |
05 | local player = game.Players:FindFirstChild(char.Name) |
06 |
07 | if GamePassService:PlayerHasPass(player, passid) then |
08 | script.Parent.Parent.Spawn.Visible = true |
09 | script.Parent.Visible = false |
10 | script.Parent.Parent.Parent.OwnedBikes.Bike 12. Visible = true |
11 | end |
12 | end |
13 |
14 | game.Workspace.ChildAdded:connect(respawned) |
Cheers,
Michael
This is the Hierarchy of the script. The Red arrow is where this code is located.
Please try this:
01 | --// Initialization |
02 |
03 | local GamePassService = game:GetService( "GamePassService" ) |
04 |
05 | --// Variables |
06 |
07 | gamepass 1 = 256633733 |
08 |
09 | --// Functions |
10 |
11 | function onCharacterSpawn(character) |
12 | local player = game.Players:GetPlayerFromCharacter(character) |
13 |
14 | if GamePassService:PlayerHasPass(player, gamepass 1 ) then |
15 | script.Parent.Parent.Spawn.Visible = true |
01 | passid = 256633733 |
02 |
03 | local GamePassService = game:GetService( "GamePassService" ) |
04 | function respawned(char) |
05 | local player = game.Players:FindFirstChild(char.Name) |
06 |
07 | if GamePassService:PlayerHasPass(player, passid) then |
08 | script.Parent.Parent.Spawn.Visible = true |
09 | script.Parent.Visible = false |
10 | script.Parent.Parent.Parent.OwnedBikes.Bike 12. Visible = true |
11 | else |
12 | end |
13 | end |
14 |
15 | 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.