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

how do i fix this error on my gamepass item giver code (error in question because of length)?

error message: 16:10:48.435 - ServerScriptService.(WORKING) Gampass Item Maker thing:8: attempt to index nil with 'Parent'

local gamepassid_ = 8172261


game.Players.PlayerAdded:Connect(function(player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassid_) then
		if player.Backpack:FindFirstChild("GravityCoil") == nil and player.Character:FindFirstChild("GravityCoil") == nil then
			game.ServerStorage:FindFirstChild("GravityCoil"):Clone()
			b.Parent = player.Backpack 
		end
	end
end)

error line:

b.Parent = player.Backpack 

2 answers

✓ Accepted answer

You didn't define "b" at all. Here's a fixed version.

local gamepassid_ = 8172261


game:GetService("Players").PlayerAdded:Connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassid_) then
        if player.Backpack:FindFirstChild("GravityCoil") == nil and player.Character:FindFirstChild("GravityCoil") == nil then
            local b = game:GetService("ServerStorage"):FindFirstChild("GravityCoil"):Clone()
            b.Parent = player.Backpack 
        end
    end
end)

4 comments

0

that fixed that error but now i have a new one lol

0

Oops, made a mistake

0

Fixed

0

k

You forgot to define the clone

local gamepassid_ = 8172261


game.Players.PlayerAdded:Connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassid_) then
        if player.Backpack:FindFirstChild("GravityCoil") == nil and player.Character:FindFirstChild("GravityCoil") == nil then
       local b =  game.ServerStorage:FindFirstChild("GravityCoil"):Clone()
            b.Parent = player.Backpack 
        end
    end
end)

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