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

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

Asked by 9 years ago

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!

01passid = 256633733
02 
03local GamePassService = game:GetService("GamePassService")
04function respawned(char)
05local player = game.Players:FindFirstChild(char.Name)
06 
07if GamePassService:PlayerHasPass(player, passid) then
08script.Parent.Parent.Spawn.Visible = true
09script.Parent.Visible = false
10script.Parent.Parent.Parent.OwnedBikes.Bike12.Visible = true
11end
12end
13 
14game.Workspace.ChildAdded:connect(respawned)

Cheers,

Michael

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

0
can you provide the hierarchy please? davness 376 — 9y
0
Edited question! Michael007800 144 — 9y
0
are you doing it on studio or on a roblox server? davness 376 — 9y
0
Roblox server. Michael007800 144 — 9y

3 answers

Log in to vote
1
Answered by 9 years ago

Please try this:

01--// Initialization
02 
03local GamePassService = game:GetService("GamePassService")
04 
05--// Variables
06 
07gamepass1 = 256633733
08 
09--// Functions
10 
11function onCharacterSpawn(character)
12  local player = game.Players:GetPlayerFromCharacter(character)
13 
14  if GamePassService:PlayerHasPass(player, gamepass1) then
15    script.Parent.Parent.Spawn.Visible = true
View all 23 lines...
0
Will do so now! Michael007800 144 — 9y
0
It looks like it worked fine! :D Cheers. Michael007800 144 — 9y
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! devSparkle 84 — 9y
0
Still people can get all the bikes ;-; Michael007800 144 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

I'd recommend putting a else before line 11.

Log in to vote
0
Answered by
A9X 10
9 years ago
01passid = 256633733
02 
03local GamePassService = game:GetService("GamePassService")
04function respawned(char)
05local player = game.Players:FindFirstChild(char.Name)
06 
07if GamePassService:PlayerHasPass(player, passid) then
08script.Parent.Parent.Spawn.Visible = true
09script.Parent.Visible = false
10script.Parent.Parent.Parent.OwnedBikes.Bike12.Visible = true
11else
12end
13end
14 
15game.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.

Answer this question