I’m making a frame that gets opened when you click on a part which requires to have a tool equipped. The problem is that it does print (“No tools equipped!”) but doesn’t open the frame I equip my tool.
I tried using the Mouse Target function to detect if the mouse is hovering the part, however it does not seem to work either.
-- Variables
local OpenPart = workspace:WaitForChild("Map"):WaitForChild("UpgradesShop"):WaitForChild("OpenPart")
local Gui = script.Parent.Parent
local Frame = Gui:WaitForChild("Frame")
local AreYouSureFrame = Gui:WaitForChild("AreYouSure")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()
---------------------------------------------------
-- Code
Mouse.Button1Down:Connect(function()
local NoToolsEquippedNotification = PlayerGui:WaitForChild("Notifications"):WaitForChild("NoToolsEquipped")
if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == false and Mouse.Target == OpenPart then
Frame.Visible = true
AreYouSureFrame.Visible = false
end
if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == true and Mouse.Target == OpenPart then
Frame.Visible = false
AreYouSureFrame.Visible = false
end
if Character:FindFirstChildWhichIsA("Tool") == nil and Mouse.Target == OpenPart then
NoToolsEquippedNotification.Visible = true
wait(1)
NoToolsEquippedNotification.Visible = false
end
end)
Can you wait like 30 minutes im at gym, i can do it when i get home. You can have a boolean true or false when ever the player equips tool and connect it to tool.Equiped event
-- Variables
local OpenPart = workspace:WaitForChild("Map"):WaitForChild("UpgradesShop"):WaitForChild("OpenPart")
local Gui = script.Parent.Parent
local Frame = Gui:WaitForChild("Frame")
local AreYouSureFrame = Gui:WaitForChild("AreYouSure")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()
---------------------------------------------------
-- Code
Mouse.Button1Down:Connect(function()
local target = Mouse.Target
local NoToolsEquippedNotification = PlayerGui:WaitForChild("Notifications"):WaitForChild("NoToolsEquipped")
if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == false and target== OpenPart then
Frame.Visible = true
AreYouSureFrame.Visible = false
return
end
if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == true and target == OpenPart then
Frame.Visible = false
AreYouSureFrame.Visible = false
return
end
if Character:FindFirstChildWhichIsA("Tool") == nil and Mouse.Target == OpenPart then
NoToolsEquippedNotification.Visible = true
wait(1)
NoToolsEquippedNotification.Visible = false
end
end)
the reason was once the frame was visible, it then became unvisible again because the next if statement ran. you didnt break the function with a return statement