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)