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

How do you make a script only apply to people with a game pass?

I have a script that makes people sprint whilst holding shift. I want this script to only apply to people that have purchased my game pass. Here's the script so far:


function onPlayerEntered(player)
	repeat wait () until player.Character ~= nil
	local s = script.SprintScript:clone()
	s.Parent = player.Character
	s.Disabled = false
	player.CharacterAdded:connect(function (char)
		local s = script.SprintScript:clone()
		s.Parent = char
		s.Disabled = false		
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

2 comments

0

Thanks but I'm really new to scripting, would I just paste the original code after the example one on the link?

1 answer

game.Players.PlayerAdded:connect(function(plr)
	if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,[[--put the gamepass id here--]]) then
		local function onPlayerEntered(player)
		    repeat wait () until player.Character ~= nil
		    local s = script.SprintScript:clone()
		    s.Parent = player.Character
		    s.Disabled = false
		    player.CharacterAdded:connect(function (char)
		        local s = script.SprintScript:clone()
		        s.Parent = char
		        s.Disabled = false      
		    end)
		end
		print(plr.Name .. " Sprint GamePass")
	else
		print(plr.Name .. " doesn't own the Sprint GamePass")
	end
end)

You could test it, but I could be wrong lol.

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