Torso ray doesnt work

Trying to make a ray fire from the torso on pressing C, but I don’t think it works cause the audio doesnt play.
Localscript:

local Debounce = false
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local Humanoid = char:WaitForChild("Humanoid",5)
game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProcessed)
	if Input.KeyCode == Enum.KeyCode.C and Debounce == false and Humanoid.WalkSpeed > 0 then			
		Debounce = true
		game.ReplicatedStorage.Remotes.Torso:FireServer()
		wait(5)
	end
	Debounce = false
end)

Server script:

local function isAlive(player)
	local char = player.Character
	if not char or not char:IsDescendantOf(game.Workspace) or not char:FindFirstChild "Humanoid" or char.Humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end
	return char
end
game.ReplicatedStorage.Remotes.Torso.OnServerEvent:Connect(function(player)
	local active = { } -- a table we've defined as active, which we'll store a bunch of characters within
	for i, v in next, game.Players:GetPlayers() do -- get all players in the game, and loop through them
		if v and v ~= player then -- if the player we're looking at in the list of the players in the game is NOT the player who sent this remote then
			local char = isAlive(v) 
			if char then -- is this player that we're looking at alive?
				active[#active + 1] = char -- add that character to the 'active list'
	local function ray(player, character)
		local torso = game.Players.LocalPlayer.Character.Torso
		local length = torso.Size.y
		local width = torso.Size.x 
		local bounding = character.PrimaryPart
		local ray = Ray.new(bounding.Position, bounding.CFrame.lookVector * (length + 5)) -- Fire a ray from our character's torso, towards its lookvector with a length of our arm size
		local ray = Ray.new(bounding.Position, bounding.CFrame.lookVector * (width + 2)) -- Fire a ray from our character's torso, towards its lookvector with a length of our arm size
		local hit, pos = game.Workspace:FindPartOnRayWithWhitelist(ray, active) -- find any parts we hit that's a part of a character's
		if hit and hit.Parent then
			local char = hit.Parent
			local hum  = hit.Parent:FindFirstChild 'Humanoid'
			if hum then
				hum:TakeDamage(99)
				game.Workspace.Folder.POW:Play()
				local vel = Instance.new 'BodyVelocity'
				vel.MaxForce = Vector3.new(0, 50000000, 0)
				vel.Velocity = Vector3.new(0, 50000, 0)
				vel.Parent = char.PrimaryPart
				delay(0.2, function()
								vel:Destroy()
								
end)
						end
						ray()
						game.Workspace.Folder.Laser:Play()
			end
		end
		end
	end
	end
end)

Torso has been deprecated. Humanoid | Documentation - Roblox Creator Hub
I believe HumanoidRootPart is the replacement.

Character.Torso is NOT deprecated. He is using Character.Torso. Not Humanoid.Torso (which is deprecated)

So, what would I replace it with?

  1. You’re doing this in a server-sided script so this wouldn’t work.
  2. I suggest using HumanoidRootPart instead of Torso (I will refrence to HumanoidRootPart with HumRP from now on), as the HumRP is more globally used, with the R15 being here.

So before that line you would have told the script who the specific player is; I will refrence the player in the script as “plr”.

local char = plr.Character or plr.CharacterAdded
local humRP = char.HumanoidRootPart

There’s no need to use :WaitForChild() here as the player can’t input C when the game is still loading.

1 Like

how would I fire a ray from the HRP in a server sided script?

You there? Or did u have to do something?