Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need selectionbox to appear when mouse is aimed at an object at a certain height?

This script is meant to have a selectionbox appear over a block if your mouse is aimed at that block and that block is a certain height. This is the script:

while wait() do  
  if script.Parent.Size.Y >= 8 then
        local player = game.Players.LocalPlayer
        local mouse = player:GetMouse()
        local selection = Instance.new("SelectionBox")
        selection.Color3 = Color3.new(0.6,0.6,0,6)
        selection.Parent = player.PlayerGui
        mouse.Move:connect(function() 
	      local target = mouse.Target
          if not target then
		    selection.Adornee = nil
          elseif target == script.Parent then
	        selection.Adornee = target
      else 
	    selection.Adornee = nil
end                
	end)
        end

This works fine when there is no conditional statement for the block's size. How do I make this work with the size constraint. Do I have to use and?

1 answer

✓ Accepted answer
while wait() do  
  if script.Parent.Size.Y >= 8 then
        local player = game.Players.LocalPlayer
        local mouse = player:GetMouse()
        local selection = Instance.new("SelectionBox")
        selection.Parent = player.PlayerGui
	selection.Color3 = Color3.new(0.6,0.6,0.6)
        mouse.Move:connect(function() 
          local target = mouse.Target
          if not target then
            selection.Adornee = nil
          elseif target == script.Parent then
            selection.Adornee = target
      else 
        selection.Adornee = nil
end                
    end)
        end

2 comments

0

Wth you just copied and pasted my code and no it does not work..

0

now it should work

This discussion is preserved as it was. New answers, comments, and votes are closed.