Lately, I’ve been trying to make a delete system but I can’t seem to find the way to tweak it. It has no errors and no trace. I assume there’s something wrong with the: if mouse.Hit.Position == workspace.FrontRoof.Position then
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Delete.MouseButton1Click:Connect(function()
if mouse.Hit.Position == workspace.FrontRoof.Position then
local SB = Instance.new(“SelectionBox”)
SB.Adornee = workspace.FrontRoof
SB.Color3 = Color3.new(255, 0, 0)
SB.Parent = workspace.FrontRoof
print(mouse.Target.Name)
end
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Delete.MouseButton1Click:Connect(function()
if mouse.Target == workspace.FrontRoof then --instead of mouse.Hit.Position it's mouse.Target
local SB = Instance.new(“SelectionBox”)
SB.Adornee = workspace.FrontRoof
SB.Color3 = Color3.new(255, 0, 0)
SB.Parent = workspace.FrontRoof
print(mouse.Target.Name)
end
end)
It’s not working because the position of the mouse isn’t the same as FrontRoof yea sure you aimed it exactly at it but you’re typically just hitting it let’s say 1 stud away from being the same position, the solution is to use magnitude(get the range of roof and mouse target position) or as @Kaid3n22 suggest, get the target instance and compare it to the FrontRoof Instance/Object.
Same issue:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Delete.MouseButton1Click:Connect(function()
if mouse.Target == workspace.FrontRoof then --instead of mouse.Hit.Position it’s mouse.Target
local SB = Instance.new(“SelectionBox”)
SB.Adornee = workspace.FrontRoof
SB.Color3 = Color3.new(255, 0, 0)
SB.Parent = workspace.FrontRoof
print(mouse.Target.Name)
end
end)
I’m pretty sure that you cant hover on a part while clicking a button (unless its mobile).
Also most times your mouse can’t be perfectly on the part.
Maybe try this?
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local SB = Instance.new("SelectionBox")
SB.Color3 = Color3.new(255, 0, 0)
SB.Parent = workspace
local deleting = false
mouse.Move:Connect(function()
SB.Adornee = mouse.Target
end)
mouse.Button1Down:Connect(function()
if mouse.Target ~= workspace.FrontRoof or not deleting then
return
end
deleting = false
mouse.Target:Destroy()
end)
script.Parent.Delete.MouseButton1Click:Connect(function()
deleting = not deleting
end)