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 a laser pointer trip and push a player?

Hello there.

I have a laser pointer on my place.

It is just a tool composed of a LocalScript and a Brick with a Mesh.

Here's the LocalScript:

transparency = 0.2

lp = script.Parent
pointing = false

function Click(mouse)

	pointing = true
	while pointing do

		laser = Instance.new("Part")
		laser.formFactor = 0
		laser.BrickColor = BrickColor.new("Bright red")
		laser.Anchored = true
		laser.CanCollide = false
		laser.Size = Vector3.new(1, 1, 1)
		laser.Transparency = transparency
		hpos = lp.Handle.Position+((lp.Handle.CFrame*CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)).lookVector/-2.5)
		dir = CFrame.new(hpos, mouse.Hit.p)
		dist = (mouse.Hit.p-hpos).magnitude
		mesh = Instance.new("CylinderMesh")
		mesh.Scale = Vector3.new(0.3, dist+0.25, 0.3)
		mesh.Parent = laser
		laser.CFrame = dir*CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)+(dir.lookVector*dist/2)
		laser.Parent = game.Workspace.CurrentCamera
		wait()
		laser:Remove()
	end
end

function Unclick(mouse)

	pointing = false
end

function Equip(mouse)

	if mouse == nil then return end

	mouse.Button1Down:connect(function() Click(mouse) end)
	mouse.Button1Up:connect(function() Unclick(mouse) end)
end

lp.Equipped:connect(Equip)

I would kindly wish to know how to make the laser push people and make them sit when the laser is pointed at them.

I thought of and tried pasting an onTouch function from a Push tool, but it simply does not work. This said tool makes the player fly away a bit when they touch my arm.

Its script is here (yes, it is the onTouched function I tried to upload to the original laser pointer script):

door = script.Parent

function onTouch(hit)
	if hit.Parent == nil then return end
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil then
		hit.Parent.Torso.Velocity=door.CFrame.lookVector * 100 -- Push the Player back
	end
end
door.Touched:connect(onTouch)

Would you help me out, please?

Thank you.

1 comment

0

when it touches the player, make the walkspeed 0 and make a trip animation maybe?

1 answer

✓ Accepted answer

Hopefully, its pretty easy!

To do this, you have to create a function, which only activates when the laser is touched, here is an Example :

laser.Touched:Connect(function(shot) -- Make it true!, once the laser is touched, the function will run!
if shot.Parent:FindFirstChild("Humanoid") then -- Detects if there is a Humanoid.
shot.Parent.Humanoid.Sit = true -- Makes Humanoid sit!
else --- Unless.... there is no Humanoid!!
return --- Return!
end
end) -- Sorry, didn't check on studio :(

That is just an example, to make the player trip, and being unable to jump/move, you can change the third line to...

shot.Parent.Humanoid.PlatformStand = true -- Boom!, Player is tripped, and unable to move unless if he presses the BACKSPACE.
wait(5)
shot.Parent.Humanoid.PlatformStand = false -- Well... just to make it fair!

Hope i helped! Good luck!

7 comments

0

Oof. Good thing that somebody answered. Where do I put this function? Make it a separate script or inject it in the already existing LocalScript?

0

Erm... you should really learn about LUA programming using WIKI, anyways, put this at end of your script, i may recommend that, since i typed " laser ", it means that it should be placed in the first script.

0

Otherwise, you get an error which says " laser is a nil value ".

0

Please accept the answer if i helped ;)

0

And one more thing, your function was fine, but the first line wasen't, it makes the script to only run when the block ( the block that the script is inside)'s touched,in other meanings, your tool's HANDLE.

0

Wait. It only works for the user, but not for other players. I mean, when I shoot myself with it, I fly away, but if I shoot anybody else, nothing happens.

0

Uhh... my function looks fine, i have tried it though, look, if your place has FilteringEnabled ON then it may not work... i guess...

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