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

How would I make a gamepass that gives the player a pet?

I have been trying to make a pet that spawns when a player buys a gamepass and follows the player with the gamepass, and that specific person, so two people can have a pet at the same time if they buy the gamepass. This is what I have so far, and its not really working, nor do I know how to make it spawn and follow the person when the have the gamepass.

repeat wait()until game.Players.LocalPlayer.Character
print("Pet Controller Loaded!")

function MovePet(pet, mode)
	local character = game.Players.LocalPlayer.Character
	local rpet = workspace.Pet
	local rmode = mode
	local inc = 0.7
	if mode == true then -- If this is true then make the pet float
		local base = character["Head"]
	else -- If its anything else other than true then make the pet go on the ground
		
		local base = character.LeftFoot
		
			
		local dir = CFrame.new(rpet.Position, base.Position).lookVector
		print(dir)
		for i=0,10,2 do
			rpet.CFrame = rpet.CFrame + (dir * inc)
			wait(0.05)
		end
	end
	end
	
while wait()do
MovePet("Pet",false)
end

If anyone could tell me how to fix this, that would be great! That's if you understand what I am trying to say haha.

2 comments

0

I haven't really experimented with game passes, but I'm pretty sure you can check if a player has a certain gamepass. Just make a function that checks for the game pass after they buy it and then spawn the pet by cloning it from wherever you have it stored and parenting it to workspace.

0

Yeah, but idk how to do that.

1 answer

Just put this in a script in serverscriptservice and make sure your pet is in ReplicatedStorage and has an ObjectValue name Owner or something.

local PassService = game:GetService("GamePassService")

function spawnpet(c)
	local pet = game.ReplicatedService.x :Clone()--x = pet name
	pet.Owner.Value = c
	pet.Parent = game.Workspace
	pet.PrimaryPart.CFrame = c.LeftFoot.CFrame * CFrame.new(0,3,-2)
end

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local check = PassService:PlayerHasPass(player,Id) --Id = gamepass id 
		if check == true then
			spawnpet(char)
		end
	end)
end)

Like I've mentioned earlier I haven't worked with gamepasses yet, but this should work.

7 comments

0

Thanks!

0

Did it work?

0

No

0

I did everything you said as well.

0

Okay, so, I copied and pasted the script into ServerScriptService, I named the object (pet) "Cube", then I replaced the "x" in the script with "Cube", and replaced "Id", with the gamepass ID, I then inserted a ObjectValue into the object (pet) and named it "Owner", and put the object (pet) into ReplicatedStorage. And it didn't work.

0

Does it need to be a LocalScript instead?

0

Sorry I haven't been able to get to you(internet trouble). Did any errors pop up because I believe you have to be online for badges to work. I suggest looking up some tutorials on youtube that detail how to use badges.

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