Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a gamepass that gives the player a pet to follow them?

Asked by 8 years ago
Edited 8 years ago

Hi, so I have been trying to make a gmaepass that gives the player a pet for ages now and I have had no luck.

I need it so when the player buys a gamepass, it will spawn in a pet for them, and the pet will follow them around, and each time the log back in the pet will spawn again and follow them around.

Here is a link to the last time I asked this questions with no answers: https://scriptinghelpers.org/questions/38004/how-would-i-make-a-gamepass-that-gives-the-player-a-pet

This is the script I am trying to use to get the pet named "Cube", to follow the player.

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

function MovePet(pet, mode)
    local character = game.Players.LocalPlayer.Character
    local rpet = workspace.Cube
    local rmode = mode
    local inc = 0.7
    if mode == true then
        local base = character["Head"]
    else

        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("Cube",false)
end

And this is the script I am trying to use to get the pet to only follow the player that owns it/has the gamepass.

local PassService = game:GetService("GamePassService")

function spawnpet(c)
    local pet = game.ReplicatedService.Cube :Clone()
    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,574089981)
        if check == true then
            spawnpet(char)
        end
    end)
end)

Nothing has been working, I don't know what else to do, so if anyone could help that would be awesome, thanks.

More detailed explanation: When the player buys the gamepass, the pet that is linked to the gamepass will spawn next to them, from then on the pet will follow them, and if the die or rejoin, the pet will teleport back to them or spawn next to them. If two player buy the gamepass, each individual pet will know what player to follow, the player that bought them. Same thing goes for if there are more than two players with pets. The pet needs to know who to follow, I don't want it spawning in and then following someone else, it needs to follow only the player that bought it.

Nothing is working, it will not spawn when the gamepass is bought, it will not follow me with or without the gamepass, it will not spawn if I relog or reset, you might as well not have any scripts at all.

This is what it said in the output tab: 23:19:34.720 - Workspace.Sound.Script:1: attempt to index global 'sound' (a nil value) 23:19:34.720 - Stack Begin 23:19:34.721 - Script 'Workspace.Sound.Script', Line 1 23:19:34.721 - Stack End 23:19:34.820 - BarnSign is not a valid member of ServerScriptService 23:19:34.821 - Stack Begin 23:19:34.821 - Script 'ServerScriptService.Script', Line 2 23:19:34.822 - Stack End 23:19:36.329 - Game passes can only be queried by a Script running on a ROBLOX game server 23:19:36.591 - Unable to find module for asset id 23:19:36.592 - Stack Begin 23:19:36.592 - Script 'Workspace.Kohl's Admin Infinite.Credit', Line 1 23:19:36.592 - Stack End Pet Controller Loaded! 23:19:38.788 - Cube is not a valid member of Workspace

Okay, so I had "Cube", in ReplicatedStorage. So I changed that part of the script to this:

local PassService = game:GetService("GamePassService")

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

But it still doesn't work.

Okay so I've now done this as well:

function MovePet(pet, mode)
    local character = game.Players.LocalPlayer.Character
    local rpet = ReplicatedStorage.Cube
    local rmode = mode
    local inc = 0.7
    if mode == true then
        local base = character["Head"]
    else

Which got rid of the error of it not being able to find it in the Workspace. But then it came up with these errors:

00:02:00.740 - Tycoon.rbxl was auto-saved to C:/Users/Benjamin/Documents/ROBLOX/AutoSaves/Tycoon_AutoSave_0.rbxl 00:02:02.872 - Workspace.Sound.Script:1: attempt to index global 'sound' (a nil value) 00:02:02.873 - Stack Begin 00:02:02.873 - Script 'Workspace.Sound.Script', Line 1 00:02:02.874 - Stack End 00:02:04.278 - Game passes can only be queried by a Script running on a ROBLOX game server 00:02:04.576 - Unable to find module for asset id 00:02:04.577 - Stack Begin 00:02:04.577 - Script 'Workspace.Kohl's Admin Infinite.Credit', Line 1 00:02:04.578 - Stack End Pet Controller Loaded! 00:02:07.131 - Players.Player1.PlayerGui.PetController:6: attempt to index global 'ReplicatedStorage' (a nil value) 00:02:07.132 - Stack Begin 00:02:07.133 - Script 'Players.Player1.PlayerGui.PetController', Line 6 - global MovePet 00:02:07.133 - Script 'Players.Player1.PlayerGui.PetController', Line 26 00:02:07.134 - Stack End

0
Explain what is supposed to happen that is not happening. cabbler 1942 — 8y
0
Haha... Everything? Nothings working, the pet doesnt follow me with or without the gamepass, nor does it spawn in when I buy the gamepass, or relog. Just nothing is working. Pot8o_Penguin 50 — 8y
0
Maybe you should try a tutorial that's easier for you, or if you really want, learn how to debug, https://scriptinghelpers.org/blog/an-essential-programming-skill-debugging OldPalHappy 1477 — 8y
0
You have to let us know any and all errors you receive when running this script. OldPalHappy 1477 — 8y
0
Okay there we go, hows that? Pot8o_Penguin 50 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

I believe the problem is in the spawn pet function

here is what i saw: local pet = game.ReplicatedService.Cube :Clone() there should not be a space between cube and :clone() try that.

0
Okay thanks! Will do! Pot8o_Penguin 50 — 8y
0
That still didn't work Pot8o_Penguin 50 — 8y
0
Yeah, its not working, would you know what to do? Pot8o_Penguin 50 — 8y
0
Is it creating the pet? Thegrimdeathzombie 40 — 8y
0
"00:02:04.278 - Game passes can only be queried by a Script running on a ROBLOX game server 00:02:04.576" If you are running a test then a gamepass cant be detected, try publishing the game to roblox then playing it from there Thegrimdeathzombie 40 — 8y
Ad

Answer this question