Gamepass Giver Not Working

Hey Everyone,
For my story game, I’m making it so that when they buy the item they get it. When I put the tool in StarterPack, all the movements work fine. But when I clone it out of replicated storage, the tool doesn’t work; it’s doesn’t move up to the player’s mouth or anything. It often gets cloned more than once aswell. Here is my script:

	MPS:PromptGamePassPurchase(game.Players.LocalPlayer, v1.ID.Value)
	MPS.PromptGamePassPurchaseFinished:Connect(function(Player, ID, WasPurchased)
		print(ID)
		print(Player.Name)
		if WasPurchased == true and game.ReplicatedStorage.GamepassTools:FindFirstChild(ID) then
			game.ReplicatedStorage.GamepassTools[ID]:Clone().Parent = Player.Backpack
		else
			game.ReplicatedStorage.GamepassTools[ID]:Clone().Parent = Player.Backpack
		end
	end);
	end)

i get no errors. Thanks for any help!

Oof I would help you , but im not a Scripter ;/

1 Like

Then why are you posting here???

The Issue might have to do with the Tool Itself. Mind sharing the code for the tool?

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.5,-.5,.3)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)
	
	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 0) then
			h.Health = h.Health + 0
		else	
			warn('Client')
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Seems like the Issue isn’t the tool but the main script, sorry! :sweat_smile:

local GamepassTools = game.ReplicatedStorage:WaitForChild("GamepassTools")

MPS:PromptGamePassPurchase(game.Players.LocalPlayer, v1.ID.Value)

MPS.PromptGamePassPurchaseFinished:Connect(function(Player, ID, WasPurchased)
	print(ID)
	print(Player.Name)
	if WasPurchased == true and game.ReplicatedStorage.GamepassTools:FindFirstChild(ID) then
		local Tool = GamepassTools[ID]:Clone()
		Tool.Parent = Player.Backpack
	else
		local Tool = GamepassTools[ID]:Clone()
		Tool.Parent = Player.Backpack
	end
end)

This should work.

1 Like

Do you know what the issue was?

Actually it didn’t work…

@CALlBRE Should it be a normal script or a local script, it’s currently a local script

This should be a serverscript as you are cloning Instances.

When it comes to gamepasses you should always manage them on the server. Someone could just make an exploit to bypass the need to buy the gamepass.

Thanks to everyone who helped, but in the end all I did was in the local script add this:

	MPS:PromptGamePassPurchase(game.Players.LocalPlayer, v1.ID.Value)

	MPS.PromptGamePassPurchaseFinished:Connect(function(Player, ID, WasPurchased)
		if WasPurchased == true then
			game.ReplicatedStorage.Events.ItemBought:FireServer(ID)
		end
end)

And I made a serverscript and added this:

MPS = game:GetService('MarketplaceService')

game.ReplicatedStorage.Events.ItemBought.OnServerEvent:Connect(function(Player, ID)
	if Player then
		if MPS:UserOwnsGamePassAsync(Player.UserId, ID) then
			local Cloned = game.ReplicatedStorage.GamepassTools[ID]:Clone()
			Cloned.Parent = Player.Backpack
		else
			local Cloned = game.ReplicatedStorage.GamepassTools[ID]:Clone()
			Cloned.Parent = Player.Backpack
		end
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		for i, gamepass in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
			if MPS:UserOwnsGamePassAsync(Player.UserId, gamepass.Name) then
				local ID = gamepass.Name
				local Cloned = game.ReplicatedStorage.GamepassTools[ID]:Clone()
				Cloned.Parent = Player.Backpack
			end
		end
	end)
end)

@CALlBRE