How would I detect what block that clicked.
The issue is that I cant figure out how they could click it with click detectors. Click detectors wouldn’t work (from what tried) cause there would be same name blocks/undetectable from what I tried.
How would I detect what block that clicked.
The issue is that I cant figure out how they could click it with click detectors. Click detectors wouldn’t work (from what tried) cause there would be same name blocks/undetectable from what I tried.
So you want to detect by using its name or something?
You can use Raycasting for that
If you want to detect what block you clicked use Raycast.
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
Mouse.Button1Down:Connect(function()
local mouseLocation = UserInputService:GetMouseLocation()
local mouseRay = Camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
local Result = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 100)
if Result and Result.Instance then
print(Result.Instance.Name)
end
end)
Hope it’s helpful !
I wrote the code exactly like this but i forgot to paste it here ;-;
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.