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

Why won't the gamepass give the tool?

wait(2) 



gpid = 233549351
tools = {"The Beans"}

GPS = game:GetService("GamePassService")
function respawned(char)
local player = game.Players:FindFirstChild(char.Name)
print("Respawned")
if char:FindFirstChild("Head") ~= nil then
print("It's a Player!")
if GPS:PlayerHasPass(player, gpid) then
print("Has GPID")
for i = 1,#tools do
game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
end
else
print("No GPID")
end
end
end
game.Workspace.ChildAdded:connect(respawned)

Thanks!

1 comment

0

If there is an output, please post it.

2 answers

✓ Accepted answer

There were three things that were potentially wrong here. 1: The name of the tool has a space 2: The connected function passes no arguments 3: (Not a real problem) Your code is not indented and it bothers me

Here is your code rewritten to address the second problem. I would strongly recommend that you use the ServerStorage service instead of Lighting.

wait(2) 

local gamePassID = 233549351
local PassService = game:GetService("GamePassService")
local tools = {"The Beans"}

function respawned(char)
    local player = game.Players:FindFirstChild(char.Name)
    print("Respawned")
    if char:FindFirstChild("Head") then
        print("It's a Player!")
        if PassService:PlayerHasPass(player, gamePassID) then
             print("Has GPID")
                for i = 1, #tools do
                    local tool = game.ServerStorage:FindFirstChild(tools[i]):Clone()
                    tool.Parent = player.Backpack
                end
        else
            print("No GPID")
        end
    end
end

game.Players.PlayerAdded:connect(respawned(char))

Or, if you wanted to, you could put all the tools in a folder (Model) inside the ServerStorage. This address both the first and second problem

wait(2) 

local gamePassID = 233549351
local PassService = game:GetService("GamePassService")
local tools = game.ServerStorage.Tools:GetChildren()

game.Players.PlayerAdded:connect(function(char)
	local player = game.Players:FindFirstChild(char.Name)
	print("Respawned")
	if char:FindFirstChild("Head") then
		print("It's a Player!")
		if PassService:PlayerHasPass(player, gamePassID) then
			print("Has GPID")
			for i, v in pairs(tools) do
				local tool = v:Clone()
				tool.Parent = player.Backpack --So much cleaner! :D
			end
		else
			print("No GPID")
		end
	end
end)

2 comments

0

game.Workspace.ChildAdded:connect(respawned(char)) W001: Unknown global 'char'

0

I just changed it

There is nothing wrong I suggest that you name the tool "TheBeans" together like that and change the script where it says tools too = {"TheBeans"} then put the tool in Lightning must not be a model.

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