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 6 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:

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function onActivate()
    local clickLocation = mouse.Hit
    if clickLocation.values.ownervalue.Value == 'DrGigaByte' then
        clickLocation:Destroy()
    end
end

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?

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

2 answers

Log in to vote
0
Answered by 6 years ago

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

Ad
Log in to vote
0
Answered by 6 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.

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function onActivate()
    local clickObject = mouse.Target
    if clickObject.values.ownervalue.Value == 'DrGigaByte' then
        clickObject:Destroy()
    end
end

tool.Activated:connect(onActivate)

Answer this question