I know there is a ton wrong with this script, can someone explain how to fix the issues. THANKS
function onPlayerEntered(newPlayer) local IDone=222805421 local IDtwo=222807114 if game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDone)then print (newPlayer.."has testing permission") if game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDtwo)then print (newPlayer.."has V.I.P.") if not game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDtwo) and not game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDone) then print (newPlayer.."is a visitor") end end end end game.Players.ChildAdded:connect(onPlayerEntered)
EDIT FOR DIITTO
local PassRank={}; --I removed the setHealth function for what im trying to do, but I saved it to my models. function assertPlayer(Player) if(PassSettings[Player.Name].VIP)then newPlayer.PlayerGui.VIPBlock:Remove() --Doesn't do this end; if(PassSettings[Player.Name].Tester)then newPlayer.PlayerGui.BetaBlock:Remove() --or this newPlayer.PlayerGui.VIPBlock:Remove() --" " end; function onPlayerEntered(newPlayer) local GamePass=game:service'GamePassService'; local ID1=222805421 local ID2=222807114 local function printf(String,...) print(string.format(String,...)); end; local Passes={ Tester=GamePass:PlayerHasPass(newPlayer,ID1) and true; VIP=GamePass:PlayerHasPass(newPlayer,ID2) and true; }; if(next(Passes))then--// If player has any pass. for Pass in next,Passes do printf('Player %s has the %q pass.', newPlayer.Name, Pass ); end; else printf('Player %s is a visitor.',newPlayer.Name); newPlayer.PlayerGui.VIPBlock:Remove() --this was my attempt at functioning with a player that has no pass wait(30) newPlayer:Kick() end PassRank[newPlayer.Name]=Passes; assertPlayer(newPlayer); end; game:service'Players'.PlayerAdded:connect(onPlayerEntered)
@mu, Easy. The issue is syntax related.
Your script has a lot of issues with syntax, like missing ends, and newPlayer
is a userdata.
Also, remember to run this server sided, with a regular script.
Fixed, and cleaned up(and I removed the earlier bug):
local PassRank={}; local setHealth=function(Character)--// Example Function coroutine.resume(coroutine.create(function() if(not Character)then repeat wait() until Player.Character; end; local Humanoid=Character:waitForChild'Humanoid'; Humanoid.MaxHealth=500; wait( 1/4 ); Humanoid.Health=500; end)); end; function assertPlayer(Player) if(PassRank[Player.Name].VIP)then --// Award player with VIP items --// Example: Player.CharacterAdded:connect(setHealth); setHealth(Player.Character); end; if(PassRank[Player.Name].Tester)then --// Give the player testing powers --// Example: Player.Chatted:connect(function(Message) if(Message:match'/test$')then local Hint=Instance.new('Hint',Player:waitForChild'PlayerGui'); Hint.Name='TestingHint'; Hint.Text='Testing'; for Increment=1,10 do Hint.Text=Hint.Text .. '.'; wait(1); end; Hint.Text='Test complete.'; end; end); end; if(not next(PassRank[Player.Name]))then --// The player is a regular person, do some stuff --// Example: advertisePurchase(Player);--// A function to try and convince them to buy VIP. end; end; function onPlayerEntered(newPlayer) local GamePass=Game:service'GamePassService'; local ID1=222805421 local ID2=222807114 local function printf(String,...) print(string.format(String,...)); end; local Passes={ Tester=GamePass:PlayerHasPass(newPlayer,ID1) and true; VIP=GamePass:PlayerHasPass(newPlayer,ID2) and true; }; if(next(Passes))then--// If player has any pass. for Pass in next,Passes do printf('Player %s has the %q pass.', newPlayer.Name, Pass ); end; else printf('Player %s is a visitor.',newPlayer.Name); end PassRank[newPlayer.Name]=Passes; assertPlayer(newPlayer); end; Game:service'Players'.PlayerAdded:connect(onPlayerEntered)
Just by looking at the structure of the script, I knew that there must be a logic error in here, assuming that you intend to have this script as a way to indicate what pass they bought.
Notice how these "if" statements are nested.
If a player has IDtwo, but doesn't have IDone, then line 7 will not execute, because the first tier of "if" statement is not true!
Therefore, your script will skip the whole chunk of code.
function onPlayerEntered(newPlayer) local IDone=222805421 local IDtwo=222807114 if game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDone)then print (newPlayer.."has testing permission") if game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDtwo)then print (newPlayer.."has V.I.P.") if not game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDtwo) and not game:GetService("GamePassService"):PlayerHasPass(newPlayer,IDone) then print (newPlayer.."is a visitor") end end end end game.Players.ChildAdded:connect(onPlayerEntered)
Rather than nest them together, try and put them together with "elseif" statements, or just separate the "if" statements altogether. Let's compare the two methods:
elseif Method
if [condition] then elseif [condition] then else [condition] then end
Separation Method
if [condition] then end if [condition] then end
Figure A: This is good for levels of permission. The script will go through the series of elseif statements until it is true. If not, the if statement altogether will be skipped.
Figure B: This is good to just let them have whatever they bought (no levels of permission).
There are two objects: 1 and 2.
Person 1 bought object 1
Person 2 bought object 2
Person 3 bought object 1 & 2