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

why is this raycasting not working when I touch this Part !?!?

It keeps on saying that cframe is not a valid member of mouse

local stud = Vector3.new(1,1,1)
local big_stud = stud * 2
local one_area = big_stud + Vector3.new(2,0,2)
print(one_area)
local part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.Size = one_area
-- getting the mouse
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
-- part touched
part.Touched:connect(function(hit)
	if mouse ~= nil then
		part.CFrame = mouse.CFrame + CFrame.new(0,0,0)
	end
end)



2 comments

0

You don't do any ray casting

0

ok then how do i do it can you please just tell me how to fix it

1 answer

That is because there’s no "CFrame" property in the mouse; I think what you meant is Mouse.Hit, and CFrames cannot be added together, they can only be multiplied, but I assume you wanted to add them together, so we must use CFrame.Hit.p which is the Vector3 of the mouse, in which CFrame and Vector3 can be added together.

Here’s how it’s done:

local stud = Vector3.new(1,1,1)
local big_stud = stud * 2
local one_area = big_stud + Vector3.new(2,0,2)
print(one_area)
local part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.Size = one_area
-- getting the mouse
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
-- part touched
part.Touched:connect(function(hit)
    if mouse ~= nil then
        part.CFrame = CFrame.new(0,0,0) + Mouse.Hit.p --also CFrame must stand before Vector3
    end
end)

4 comments

0

thx dude you just saved my day

0

can you accept my answer ? thx

0

i cant i dont know why i kept on clicking accept answer it refresh and then it does nothing

0

try another browser

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