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 get this laser to push players backwards?

Here is the script:

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
 
tool.Equipped:connect(function(mouse)
	print("Tool equipped!")
	
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 800)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Bright red")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		
		local distance = (tool.Handle.CFrame.p - position).magnitude
		beam.Size = Vector3.new(0.3, 0.3, distance)
		beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		
		game:GetService("Debris"):AddItem(beam, 0.1)
		
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
			
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
			
			if humanoid then
				humanoid:TakeDamage(30)
				
			end
		end
	end)
end)

I have been using this script to make a laser so far, and I would like it to push the player it is hitting. I just can't figure out how. Please help.

2 answers

✓ Accepted answer

This might work, not sure though.

Script:

if humanoid then
	humanoid:TakeDamage
	local root = humanoid.RootPart
	if beam then
		root.CFrame = CFrame.new(beam, Vector3.new(root.X,root.Y,root.Z)) * CFrame.new(0,0, amount).p -- amount = push back force, sense the beam should be pointing directly at it or directly away from it, it should eather flip around or not.
	end
end

Resources: How to stop people from going to close to a part?

3 comments

0

when I try that it says this: Players.OPuff_TheCat.Backpack.Lazer Pointer.LocalScript:35: Expected '(', '{' or , got 'local'

0

ops where is says humanoid:takeDamage do this humanoid:TakeDamage(30) sorry!

0

thx

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