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

Why doesn't this gamepass script work? I have tried everything.

This is the script. I don't know why it doesn't work.

script.Parent.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChild("Humanoid") then
	game.Players.PlayerAdded:Connect(function(player)
		local MS = game:GetService("MarketplaceService")

	if MS:UserOwnsGamePassAsync(player.userId, 16777517) == true then
			script.Parent.CanCollide = false
			script.Parent.Transparency = 0.8
		else
			MS:PromptGamePassPurchase(player, 16777517)
		end
	end)
	end
end)

1 comment

0

I am making sure to touch the part

1 answer

Manby, you misunderstand the PlayerAdded Event.

PlayerAdded is only fired when a new player is added, doesn't has to be the player who hit the part. instead of PlayerAdded, use GetPlayerFromCharacter.

here's the fixed version of your script. Make sure it is a server script.

script.Parent.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)
		local MS = game:GetService("MarketplaceService")
		if MS:UserOwnsGamePassAsync(player.userId, 16777517) == true then
			script.Parent.CanCollide = false
			script.Parent.Transparency = 0.8
		else
			MS:PromptGamePassPurchase(player, 16777517)
		end
	end
end)

2 comments

0

And https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded to know how to properly use the PlayerAdded event

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