Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why is my gamepass handler not giving players the items?

pcall(function()
	game.Players.PlayerAdded:connect(function(player)
		if game.GamePassService:PlayerHasPass(player,574426548) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 10
					char.Humanoid.Health = char.Humanoid.Health + 10
					game.Lighting.WoodenSword:Clone().Parent=player.Backpack
				end
			end)
		elseif game.GamePassService:PlayerHasPass(player,574427239) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
					char.Humanoid.Health = char.Humanoid.Health + 25
					game.Lighting.SubspaceTripmine:Clone().Parent=player.Backpack
				end
			end)
		elseif game.GamePassService:PlayerHasPass(player,574430612) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 50
					char.Humanoid.Health = char.Humanoid.Health + 50
					game.Lighting.EpicKatana:Clone().Parent=player.Backpack
				end
			end)
		elseif game.GamePassService:PlayerHasPass(player,574437515) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 75
					char.Humanoid.Health = char.Humanoid.Health + 75
					game.Lighting.RayGunBio:Clone().Parent=player.Backpack
				end
			end)
		elseif game.GamePassService:PlayerHasPass(player,574439700) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 100
					char.Humanoid.Health = char.Humanoid.Health + 100
					game.Lighting.Phoenix:Clone().Parent=player.Backpack
				end
			end)
		elseif game.GamePassService:PlayerHasPass(player,574441188) then
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 200
					char.Humanoid.Health = char.Humanoid.Health + 200
					game.Lighting["Ro-Orb"]:Clone().Parent=player.Backpack
					game.Lighting.Darkheart:Clone().Parent=player.Backpack
				end
			end)
		end
	end)
end)

script will not give the player what he bought please help.

1 answer

✓ Accepted answer

The way your code is written, the first gamepass that the Player has purchased, in the order you have typed them, is the only one they get. elseif doesn't trigger if a previous if or elseif in the same 'tree' triggered:

pcall(function()
    game.Players.PlayerAdded:connect(function(player)
        if game.GamePassService:PlayerHasPass(player,574426548) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 10
                    char.Humanoid.Health = char.Humanoid.Health + 10
                    game.Lighting.WoodenSword:Clone().Parent=player.Backpack
                end
            end)
        end
if game.GamePassService:PlayerHasPass(player,574427239) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
                    char.Humanoid.Health = char.Humanoid.Health + 25
                    game.Lighting.SubspaceTripmine:Clone().Parent=player.Backpack
                end
            end)
        end
	if game.GamePassService:PlayerHasPass(player,574430612) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 50
                    char.Humanoid.Health = char.Humanoid.Health + 50
                    game.Lighting.EpicKatana:Clone().Parent=player.Backpack
                end
            end)
        end
	if game.GamePassService:PlayerHasPass(player,574437515) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 75
                    char.Humanoid.Health = char.Humanoid.Health + 75
                    game.Lighting.RayGunBio:Clone().Parent=player.Backpack
                end
            end)
        end
	if game.GamePassService:PlayerHasPass(player,574439700) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 100
                    char.Humanoid.Health = char.Humanoid.Health + 100
                    game.Lighting.Phoenix:Clone().Parent=player.Backpack
                end
            end)
	end       
	if game.GamePassService:PlayerHasPass(player,574441188) then
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 200
                    char.Humanoid.Health = char.Humanoid.Health + 200
                    game.Lighting["Ro-Orb"]:Clone().Parent=player.Backpack
                    game.Lighting.Darkheart:Clone().Parent=player.Backpack
                end
            end)
        end
    end)
end)

3 comments

0

ahhh ok ty

0

urm idk why but it sill will not give the items to the players and it doesnt change their health as well.

0

nvm fixed the problem it works now.

This discussion is preserved as it was. New answers, comments, and votes are closed.