Hello.

The water turret tool is effectively pushing me when I aim at myself. However, when I shoot at other players, it does nothing to them.

The tool makes a part called laser when the left mouse button is pressed and when I touch it, it makes me sit and pushes me a few studs away. That is how it is supposed to work for players.

The game I am working on is non-FE.

Here is how this LocalScript looks like:

transparency = 0.5

lp = script.Parent
pointing = false
local spray = lp.Handle.FoamSound

function Click(mouse)
spray:Play()
	pointing = true
	while pointing do

		laser = Instance.new("Part")
		laser.formFactor = 0
		laser.BrickColor = BrickColor.new("Toothpaste")
		laser.Material = ("Ice")
		laser.Anchored = true
		laser.CanCollide = false
		laser.Size = Vector3.new(1, 1, 1)
		laser.Transparency = transparency
		local hpos = lp.Aim.Position
		local dir = CFrame.new(hpos, mouse.Hit.p)
		local dist = (mouse.Hit.p-hpos).magnitude
		local 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
		local particle = Instance.new("ParticleEmitter")
		particle.Texture = ("rbxassetid://304113188")
		particle.LightEmission = 0
		particle.LightInfluence = 1
		particle.Parent = laser
		particle.Speed = NumberRange.new(80)
		particle.Rate = 300
		laser.Touched:connect(function(shot)
			if shot.Parent:FindFirstChild("Humanoid") then
			print("Humanoid is hit")
			shot.Parent.Humanoid.Sit = true
			shot.Parent.Torso.Velocity=laser.CFrame.lookVector * 50
			else
			return
			end
		end)
		wait(0.02)
		laser:Remove()
	end
end

function Unclick(mouse)

	pointing = false
	spray:Stop()
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)

Thank you. I need your help.

1 comment

0

connect is deprecated, switch to Connect. Remove is deprecated, switch to Destroy.