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

Why won't the gamepass give the tool?

Asked by 9 years ago
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!

0
If there is an output, please post it. Grenaderade 525 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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)
0
game.Workspace.ChildAdded:connect(respawned(char)) W001: Unknown global 'char' iiCasual 20 — 9y
0
I just changed it DewnOracle 115 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.

Answer this question