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

My script that changes visibility isn't working. Does anyone know the issue?

Asked by
Amsupr -1
5 years ago

Ok so basically this is a section of my script that is for a gamepass gui script. I want this to make a textlabel visible if they own the gamepass, but it's not becoming visible for me. I'm new to scripting so an explanation would be helpful too!

Here:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,productId) then
    script.Parent.Selectable = false
    script.Parent.Text = '--'
    script.Parent.Parent.Owned.Visible = true 
     else script.Parent.Parent.Owned.Visible = false
end

Thank you, Amsupr

1
Only serverscripts can check if a user owns an asset. Only a localscript can change gui. Use a remote event and your problem should be fixed. RubenKan 3615 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You need to use RemoteFunction for checking gamepass

--// ServerScript (put RemoteFunction to ReplicatedStorage and change name to CheckGamePass)
checkGamePass = game.ReplicatedStorage.CheckGamePass
function checkGamePass.OnServerInvoke (plr,ID)
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,ID)
end

--// LocalScript
if game.ReplicatedStorage.CheckGamePass:InvokeServer(GamePassID) then
    script.Parent.Selectable = false
    script.Parent.Text = '--'
    script.Parent.Parent.Owned.Visible = true 
else
    script.Parent.Parent.Owned.Visible = false
end
0
thank you :) Amsupr -1 — 5y
Ad

Answer this question