So basically I'm trying to make it so if I click on a block with a hammer it checks if the player that's clicking is the owner of the block here's what I have:
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 |
05 | local function onActivate() |
06 | local clickLocation = mouse.Hit |
07 | if clickLocation.values.ownervalue.Value = = 'DrGigaByte' then |
08 | clickLocation:Destroy() |
09 | end |
10 | end |
11 |
12 | tool.Activated:connect(onActivate) |
I'm getting an error saying " values is not a valid member of CFrame" is there any way I could access the hit part and destroy it?
The only thing you are doing wrong is you are using "Mouse.Hit" which specifies what position the mouse is pointing to and I believe in which direction, but you want to know what object the mouse is pointing to, so you have to use the "Mouse.Target" event that will specify which block/basepart the mouse is currently pointing at.
The only thing you have to do Is change a line in your script, here, I did that for you, I also replaced "clickLocation" to "clickObject" cause that suits it a little bit better.
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 |
05 | local function onActivate() |
06 | local clickObject = mouse.Target |
07 | if clickObject.values.ownervalue.Value = = 'DrGigaByte' then |
08 | clickObject:Destroy() |
09 | end |
10 | end |
11 |
12 | tool.Activated:connect(onActivate) |