Hello! Does anyone know why the below script only works some of the time? Unless it's the first player to join the server, in which case it seems to always work, otherwise it only works like 1/4 of the time it seems.
local mps = game:GetService("MarketplaceService") local gamepass = ####### game.Players.PlayerAdded:Connect(function(player) if mps:UserOwnsGamePassAsync(player.UserId, gamepass) then player.PlayerGui.RegularGui.Open.Visible=false --hides regular gui script.VIPGui:Clone().Parent = player.PlayerGui --clones script child vipgui into players gui end end)
well, it's possible that expressions such as player.PlayerGui
are nil
,
so i'd recommend using WaitForChild()
like so
local mps = game:GetService("MarketplaceService") local gamepass = ####### game.Players.PlayerAdded:Connect(function(player) if mps:UserOwnsGamePassAsync(player.UserId, gamepass) then player:WaitForChild("PlayerGu"):WaitForChild("RegularGui").Open.Visible=false script.VIPGui:Clone().Parent = player.PlayerGui end end)
you could probably make the code a bit cleaner than just putting a bunch of WaitForChild()
s next to each other