I'm trying to access a certain player's backpack from Workspace and it's not working. I've tried a print statement as you can see below, but nothing is showing in the output. I give thanks and credit to saSlol2436 for helping me make this script.
local hasFlag = true
function accessBackpack(hit)
if hit and hit.Parent then
local chara = hit.Parent
local player = game.Players:GetPlayerFromCharacter(chara)
local backpack = player:FindFirstChild("Backpack")
local flag = backpack:FindFirstChild("RedFlag")
if flag and flag.Parent == backpack and hasFlag == true then
else
print("RedFlag is not apparant")
end
end
end
script.Parent.RedFlag.Handle.Touched:Connect(function(char)
if char ~= nil then
local player = game.Players:GetPlayerFromCharacter(char.Parent)
if player then--check if they are a player
if char.Parent:FindFirstChild("Humanoid") then
if char.Parent.Humanoid.Health ~= 0 then--if they are still alive
print(player.Name .. " has the Red Flag!")
char.Parent:FindFirstChild("Humanoid").Died:Connect(function()
if char.Parent:FindFirstChild("RedFlag") or accessBackpack() then --if they die and they have the flag in their hand or backpack
local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
FlagClone.Parent = game.Workspace
FlagClone.Handle.CFrame = CFrame.new(char.Parent.Head.Position)
FlagClone.Handle.Anchored = true
end
end)
end
end
end
end
wait(2)
end)

2 comments
You should print debug all the values, see what they are worth, and see if anything is wrong after that.
So like: print(backpack.Parent) and see who the parent is? Because I've already tried that and nothing in the output