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

Player getting speed coil even though they already have it in backpack?

I have a speed coil gamepass, when the player joins the game, we check if they have the speed coil gamepass. If they do, then we give them the speed coil.

So what's happening right now is, that whenever they join the game, they get the speed coil. But before giving them, I want to check if they already have it in their backpack. In simpler words, let's suppose the player joins the game. They own the game pass and get their speed coil. Now they leave the game and join again. They get the speed coil again. Now in this way, they can easily spam their backpack.

So this is what I tried (normal script):

local SpeedCoilId = GamePassIdHere

game.Players.PlayerAdded:Connect(function(player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, SpeedCoilId) then

		if not player.Backpack:FindFirstChild("SpeedCoil") then

			local clonedSpeedCoil = game.ReplicatedStorage.Tools.SpeedCoil:Clone()
			clonedSpeedCoil.Parent = player.Backpack
			clonedSpeedCoil.Parent = player.StarterGear
		end


	end

end)

I usually use this type of check whenever I give the ability to players to get items. And not just keep clicking that item to spam their inventory. I did something similar here but with no success. The player still keep getting their speed coil everytime they join.

How can I stop this? Is it because the script runs before their backpack has been loaded? Any way to fix this?

Thanks for any help

2 answers

✓ Accepted answer

You can use a wait(1) at the first part of the code, if it even works lol.

you can actually make a boolean value, it will be true if you have cloned the coil and save it to datastore.

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