I coded a cape script. I'm not that familiar with premium only scripting, but I tried making this cape premium only in the first lines. This didn't exactly work. Non premium users also have access to the cape. Any fixes?

-- this is my revised cape script
-- I put it in a local script in StarteGui


local specials = {"700000002", "scrapbun", 255137888, "Player1"} -- String for username, number for userid
local capeColor = BrickColor.new("Really black")
local capeLength = 5
local renderCap = 200 -- Stop rendering capes for players over 200 studs away
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local runServ = game:GetService("RunService")

if player.MembershipType ~= Enum.MembershipType.Premium then
	function canUseCape(player)
		return false
	end
end

if player.MembershipType == Enum.MembershipType.Premium then
	function canUseCape(player) --
		return true
	end
	
	function applyCape(char) -- Where all the magic happens
		if (game.Workspace.CurrentCamera.Capes:FindFirstChild("Cape" .. char.Name)) then
			game.Workspace.CurrentCamera.Capes["Cape" .. char.Name]:Destroy()
		end

		while (char and not char.Parent and not char:FindFirstChild("Torso")) do
			runServ.Heartbeat:wait()
		end

		if (not char or not char.Parent) then
			return "Uh oh!"
		end

		local cape = Instance.new("Model", game.Workspace.CurrentCamera.Capes)
		cape.Name = "Cape" .. char.Name

		local bits = {}
		local isShowing = true

		for x = 1, 10 do
			if (not bits[x]) then
				bits[x] = {}
			end

			for y = 1, capeLength / 0.2 do
				local p = Instance.new("Part", cape)
				p.FormFactor = "Custom"
				p.Size = Vector3.new(0.2, 0.2, 0.2)
				p.BrickColor = capeColor
				p.CanCollide = false
				p.Anchored = true
				p.Material = "Neon"

				bits[x][y] = p
			end
		end

		spawn(function() -- So noobs don't have to thread this themselves
			while (cape and cape.Parent and char and char:FindFirstChild("Torso") and char.Parent == game.Workspace) do
				if ((char:GetModelCFrame().p - game.Workspace.CurrentCamera.CoordinateFrame.p).magnitude <= 200) then
					if (not isShowing) then
						for x = 1, #bits do
							for y = 1, #bits[x] do
								bits[x][y].Transparency = 0
							end
						end

						isShowing = true
					end

					for x = 1, #bits do
						for y = 1, #bits[x] do
							local bit, lastPos = bits[x][y], bits[x][y].CFrame - Vector3.new(0, 0.2, 0)
							local bitTop = y > 1 and bits[x][y - 1] or nil
							local cf

							if (bitTop) then
								local pos, lookAt = bitTop.CFrame * CFrame.new(0, 0, -0.1), lastPos.p
								cf = CFrame.new(pos.p, lookAt) * CFrame.new(0, 0, -0.1)
							else
								local pos, lookAt = char.Torso.CFrame * CFrame.new(0, 1.1, 0.6) * CFrame.new(x * 0.2 - 1.1, (-y + 1) * 0.2 - 0.1, 0), lastPos.p
								cf = CFrame.new(pos.p, lookAt) * CFrame.new(0, 0, -0.1)
							end

							bit.CFrame = cf
						end
					end
				elseif (isShowing) then
					for x = 1, #bits do
						for y = 1, #bits[x] do
							bits[x][y].Transparency = 1
						end
					end

					isShowing = false
				end

				runServ.RenderStepped:wait()
			end

			if (cape and cape.Parent) then
				cape:Destroy()
			end
		end)
	end

	function playerAdded(player)
		if (canUseCape(player)) then
			player.CharacterAdded:connect(function(char)
				applyCape(char)
			end)

			if (player.Character and player.Character.Parent == game.Workspace) then
				applyCape(player.Character)
			end
		end
	end
	
	if (game.Workspace.CurrentCamera:FindFirstChild("Capes")) then
		game.Workspace.CurrentCamera.Capes:ClearAllChildren()
	else
		Instance.new("Model", game.Workspace.CurrentCamera).Name = "Capes"
	end

	for i, player in pairs(game.Players:GetPlayers()) do
		playerAdded(player)
	end
end

game.Players.PlayerAdded:connect(playerAdded)