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

How do I make it so that if the mouse looks at a certain part, it does an event?

Asked by 10 years ago

I can't make it so that if the mouse looks at a certain part, it does an event, here's what I've done:

mouse = game.Players.LocalPlayer:GetMouse()

function KnockCharOut()
    bv = Instance.new("BodyVelocity", game.Players.LocalPlayer.Character.Torso)
    bv.velocity = game.Players.LocalPlayer.Character.Torso.CFrame.lookVector *5
    game.Debris:AddItem(bv, 0.5)
    game.Players.LocalPlayer.Character.Humanoid.Sit = true
    for i = 1, 300 do
        wait(0)
        game.Players.LocalPlayer.Character.Humanoid.Sit = true
        game.Players.LocalPlayer.Character.Humanoid.Jump = false
    end
end
if mouse.Target == script.Parent then
    game.Workspace.Scary:Play()
    KnockCharOut()
end

Note this is for my Unexpected place.

I don't know how to do it, can you help? Thanks.

1 answer

Log in to vote
0
Answered by 10 years ago

"LocalPlayer = nil" is why it doesn't work, that is why it is breaking Put it in a LocalScript, and it should work.

Ad

Answer this question