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

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

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

✓ Accepted answer

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

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