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!

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.

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:

--// 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)
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
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.

Answer this question