Changing Character to Roblox Character Gamepass

Hello everyone! This script is not working correctly and it keeps looping when a player who does not have the gamepass joins and keeps printing Works over and over. Why is that?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local char = game:GetService("ServerStorage").StartChar
local gamePassID = 12191214

Players.PlayerAdded:Connect(function(player)
		local hasPass = false

		local success, message = pcall(function()
			hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
		end)
		if not success then
			warn("Error while checking if player has pass: " .. tostring(message))
			return
		end

	player.CharacterAdded:Connect(function(plrChar)
		if not hasPass then
			wait() -- this isnt really necessary
			local newChar = char:Clone()
			newChar.Parent = workspace
			newChar:MoveTo(plrChar:WaitForChild("HumanoidRootPart").Position)
			newChar.Name = player.Name
			player.Character = newChar
			print("Works")
			plrChar:Destroy()
			game:GetService("ReplicatedStorage").LoadAnims:FireClient(player, newChar)
		end
	end)
end)
1 Like