Headless Head Gamepass

Due he says that setting the transparency to 1 destroys the head

This fixed my issue works in game and in studio now. Thank you for the help and thank you for the time. Much much appreatied

1 Like

That is not true at all. It must be something else destroying the head. Setting the heads transparency to 1 will not destroy it. Also, OP author, please read my post far above, it has really important things in it that your are lacking, but you seem to be ignoring it just because I didn’t give you straight code. Also guys, make sure you explain what the code does to him. He doesn’t know how to code at all.

To expand on what your issue likely was, the player loading and character loading are two different things. If you just check for a player loading into a game and immediately try to access the character, it won’t exist. @TDtheTV’s solution fixes it for you because it waits for the character to load in.

Wait a sec, there is still a lot wrong with your script. For the UserOwnsGamepassAsync, please wrap it in a pcall(), or your script will not be reliable. Also, don’t use random wait()s in your script, also unreliable.

Finally, please don’t just ignore my posts because I don’t spoon feed you everything. Out of everyone here so far, I am the most experienced. We are not supposed to spoon feed you answers, we are supposed to make you understand. And it is detrimental to your health when you skip past really important pieces of advice in favor of a spoon fed script that is unreliable.

so what do i add to fix that? do i just remove all the waits?

Yeah, this is useful in case buying the gamepass breaks

Also explain the code he is not a scripter

My script is ok, just adding a pcall will make it 100% effective, but that is the creator choice

The wait(0.1) is not neccisary. Also, to wrap it in a pcall, do this:


local ownsGamepass = nil

pcall(function()
    ownsGamepass = — user owns game pass stuff here
end)

if ownsGamepass then
    —do rest of stuff
end

Pcalls are very neccisary. Also delete the wait(0.1) thing.

I’m not sure where to put that script?

Put that before the if statement.

1 Like

Firstly, there’s no need for any wait()'s here.
Secondly, there is no need for any FindFirstChild()'s.
Thirdly, you don’t need to return the game pass id.

That being said, I took my time to enhance your code below and explain a few important things.

local Players = game:GetService('Players')
local MarketplaceService = game:GetService('MarketplaceService')
local GamePassId = 0000000000 -- Your game pass id.


local function PlayerAdded(Player)
	local function CharacterAdded(Character)
		local Check = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamePassId)
		if Check then
			local Head = Character.Head -- Their head will exist when the CharacterAdded is fired.
			Head.Transparency = 0.99 -- Making it one will hide the player's name (above their character).
			Head.face:Destroy() -- Destroys the face decal.
		end
	end
	local Character = Player.Character
	if Character then 
		-- Sometimes, the character is added before the CharacterAdded event can be fired (due to delays, and WaitForChild()'s).
		-- If so, run the CharacterAdded event if the character is already added.
		coroutine.resume(coroutine.create(function()
			CharacterAdded(Character)
		end))
	end
	Player.CharacterAdded:Connect(CharacterAdded)
end


local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
	local Player = GetPlayers[i]
	coroutine.resume(coroutine.create(function()
		-- Runs the PlayerAdded in parrallel for every player that was added before the event is fired.
		-- As explained above, unexpected delays and WaitForChild()'s can cause this event to not fire when the player is added.
		PlayerAdded(Player)
	end))
end
Players.PlayerAdded:Connect(PlayerAdded)

Good luck on your project.

4 Likes

Can you send the link on the devforum to coroutine?

Just put this in my game works in studio and ingame thank you so much!

1 Like

coroutine is similar to spawn(), and it doesn’t have the built-in wait() spawn has.
More information here: coroutine | Documentation - Roblox Creator Hub

This is a good script man, even better than my solution. Such a pretty and organized code!

1 Like

No need to send anymore, I found it.

Doesn’t the UserOwnsGamepassAsync need to be wrapped in a pcall?

1 Like

No.
More information: MarketplaceService | Documentation - Roblox Creator Hub

1 Like