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

Find the person who clicked?

Trying to make a script where you click a brick, it follows your mouse. But I don't understand how to find who clicked it

Normal script inside of a Click Detector inside of a brick that's in a model

script.Parent.MouseClick:connect(function(player)
local Mouse = player.Mouse
script.Parent.CFrame = CFrame.new(-0.02,Mouse.X,-0.05,Mouse.Y)
end)

Thank you.

1 comment

0

You can't get a mouse through a server script. I think you can Adornee ClickDetectors to a part through a localscript.

1 answer

Your script have some mistakes

  • Instead of player.Mouse you need to use player:GetMouse()

  • To get mouse position you need to use mouse.Hit, and to get X,Y,Z use mouse.Hit.X and etc.

  • To make part always follow your mouse, you need to add infinite loop

  • To make mouse not detect your part as target, you need to put it in player's character.

With fixing all that mistakes, you will have script like that:

script.Parent.MouseClick:connect(function(player)
	local Mouse = player:GetMouse()
	script.Parent.Parent = player.Character
	while true do
	wait()
		script.Parent.Parent.CFrame = CFrame.new(Mouse.Hit.X,Mouse.Hit.Y,Mouse.Hit.Z)
	end
end)

1 comment

0

It won't work. I told you the script is inside a click detector in a brick inside of a model.

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