So I have this mail carrier job script in my game. The job itself works, but I can’t figure out how to prevent the player from taking multiple envelopes. Here’s the main part of the script:
Prompt.Triggered:Connect(function(Player)
if Player.Team.Name == "Mail Carrier" then
if Player:FindFirstChild("Mail") ~= nil then -- Has mail in player
WarnPlayer(Player)
else -- Might have mail in character
if Player.Character:FindFirstChild("Mail") ~= nil then -- Has mail in character
WarnPlayer(Player)
else -- Doesn't have mail at all
local Clone = Mail:Clone()
Clone.Parent = Player.Backpack
Event:FireClient(Player)
end
end
else
WarnPlayer(Player)
end
end)
The WarnPlayer function just tells the player that they already have mail. Also, I’m not getting any errors.
if Player:FindFirstChild("Mail")
you will probably want to make this into
if Player.Backpack:FindFirstChild("Mail")
Not sure why you have a lot of else
& if
statements
If the Mail
is a Tool Object, you’re referencing the Player Object & not the Backpack
Try this:
Prompt.Triggered:Connect(function(Player)
if Player.Team.Name == "Mail Carrier" then
if Player.Backpack:FindFirstChild("Mail") == nil and Player.Character:FindFirstChild("Mail") == nil then
local Clone = Mail:Clone()
Clone.Parent = Player.Backpack
Event:FireClient(Player)
else
WarnPlayer(Player)
end
else
WarnPlayer(Player)
end
end)
You could have a table of names and when they take the item, check if their name is in the table, if it’s not, use put them in the table and give it to them
(I can’t give code rn cause I’m on mobile)
It told me that I had mail when I didn’t even have mail yet.
Yeah, I forgot to reference the Backpack @JackscarIitt and @DarkDanny04.