So i created a game pass and i wanted to link it with a part that would give you the tool if you have a game pass. But the script won't work at line 21.
Here's my code
local debounce = true
local weapon = game.ReplicatedStorage.Shuriken
local player = game:GetChildren("Players").localPlayer
local GamePassService = game:GetService('GamePassService')
local player1 = game.Players.LocalPlayer
local part = script.Parent
local cooldown = 3
id = 12345 --gamepass id
local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset?id=3302699870"
sound.Parent = script.Parent
local function GiveTool(plr)
local hit = plr.Parent
local humanoid = hit:FindFirstChildWhichIsA("Humanoid")
if humanoid and debounce == true then
print("pass1")
local bag = game.Players:GetPlayerFromCharacter(hit).Backpack
if GamePassService:PlayerHasPass(player1.userid, id) then -- there is an error
print("pass2")
local weaponCopy = weapon:Clone()
weaponCopy.Parent = bag
sound:Play()
debounce = false
wait(cooldown)
debounce = true
end
end
end
part.Touched:Connect(GiveTool)
Can you explain why it doesn't work ?
ERROR : Workspace.Model.Give.ScriptGiver:21: attempt to index upvalue 'player1' (a nil value)

1 comment
Is this a script or localscript?