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)
If you want to check for tools, you have to check both the backpack and character (since the tools are in the character if they are equipped). You also have to remember that 'Backpack' doesn't have a capital P. Here's an example function for checking for the tool:
local function playerHasTool(player, toolName) local tool = player.Backpack:FindFirstChild(toolName) or player.Character:FindFirstChild(toolName) if tool then return true else return false end end thing.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if playerHasTool(player, "MediterraneanAvenue") and playerHasTool(player, "BalticAvenue") then --do stuff end end)
Hope this helps!
just do
if Player.Backpack:FindFirstChild("MediterraneanAvenue") and Player.Backpack:FindFirstChild("BalticAvenue") then ... end