This is my script: I want to detect if two tools (MediterraneanAvenue and BalticAvenue) are there in the player's backpack when he touches a part and want to give my conditions accordingly. But when I tried this it didn't work! Can someone please help me?
local Part = script.Parent
Part.Touched:Connect(function(HIT)
local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
local FindMediterraneanAvenue = Player.Backpack:FindFirstChild("MediterraneanAvenue")
local FindBalticAvenue = Player.BackPack:FindFirstChild("BalticAvenue")
local H = HIT.Parent:FindFirstChild("Humanoid")
if H and not FindMediterraneanAvenue then
Player.PlayerGui.MediterraneanAvenue.StartUp.Visible = true
elseif H and FindMediterraneanAvenue and not FindBalticAvenue then
print("You need to own all lots first.")
elseif H and FindMediterraneanAvenue and FindBalticAvenue then
Player.PlayerGui.MediterraneanAvenue.ClickBuild.Visible = true
end
end)
Part.TouchEnded:Connect(function(part) -- leaves the part
if game.Players:GetPlayerFromCharacter(part.Parent) then -- if the part leaving is a player
local Player = game.Players:GetPlayerFromCharacter(part.Parent) -- the player
if Player.PlayerGui.MediterraneanAvenue.StartUp.Visible == true then -- if the gui is open
Player.PlayerGui.MediterraneanAvenue.StartUp.Visible = false
if Player.PlayerGui.MediterraneanAvenue.ClickBuild.Visible == true then
Player.PlayerGui.MediterraneanAvenue.ClickBuild.Visible = false
end
end
end
end)

2 comments
should I put if playerHasTool(player,"MediterraneanAvenue") == true?
You don't need to, since true == true just evaluates to true anyway, so you can just do it like it is in the example.