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

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

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?

5 comments

0

mouse.Target not mouse.Hit

0

idk what you are trying to do but I would use mouse.Target

0

That worked, thank you0.

0

yeh mouse.Hit is a cframe value lol

0

yeh mouse.Hit is a cframe value lol

2 answers

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)

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