I've tried this script below, but its not working. The function called accessBackpack (line 3) is the one i need help with. I made an if statement (line 22) it's supposed to do a check to see if the Flag is in the player's hand or backpack.
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
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)
Please help me.

8 comments
There was no error message in the output
Of course not, as that is not a lua error. It runs fine in Lua, just not the way you want it to.
I was reading 2 questions and must have confused the two on errors, sorry.
its ok
I have a question about the return statement. So by pass values, u mean like: return(RedFlag)? I don't really understand it. I've looked at the link and YouTube videos and I still don't understand it. And where would I put it? At the end of the accessBackpack() function? Please help me understand this.
you can put it anywhere and you can have more than 1, such as you could have 1 in an if statement and 1 in the else. Once you return, the function stops. Also no (), just return RedFlag
ok thx
I just did what u said and it didn't clone