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

Find the person who clicked?

Asked by 9 years ago

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.

0
You can't get a mouse through a server script. I think you can Adornee ClickDetectors to a part through a localscript. HungryJaffer 1246 — 9y

1 answer

Log in to vote
-2
Answered by
Mokiros 135
9 years ago

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)
0
It won't work. I told you the script is inside a click detector in a brick inside of a model. Grenaderade 525 — 9y
Ad

Answer this question