Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm trying to make a delete hammer and I'm having problems, help?

Asked by 7 years ago

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:

01local tool = script.Parent
02local player = game.Players.LocalPlayer
03local mouse = player:GetMouse()
04 
05local function onActivate()
06    local clickLocation = mouse.Hit
07    if clickLocation.values.ownervalue.Value == 'DrGigaByte' then
08        clickLocation:Destroy()
09    end
10end
11 
12tool.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?

0
mouse.Target not mouse.Hit greatneil80 2647 — 7y
0
idk what you are trying to do but I would use mouse.Target greatneil80 2647 — 7y
0
That worked, thank you0. ExtremeNyanCat123 32 — 7y
0
yeh mouse.Hit is a cframe value lol User#19524 175 — 7y
0
yeh mouse.Hit is a cframe value lol User#19524 175 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

" mouse.Target not mouse.Hit" was the answer

Ad
Log in to vote
0
Answered by 7 years ago

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.

01local tool = script.Parent
02local player = game.Players.LocalPlayer
03local mouse = player:GetMouse()
04 
05local function onActivate()
06    local clickObject = mouse.Target
07    if clickObject.values.ownervalue.Value == 'DrGigaByte' then
08        clickObject:Destroy()
09    end
10end
11 
12tool.Activated:connect(onActivate)

Answer this question