I have raycasting here in the localscript

-- Cast Ray
		local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
		local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		shootRemote:FireServer()
		tracerRemote:FireServer(position)
		-- Hit Detection
		if touch then
			hitRemote:FireServer()
		end

Then once I send it to the server here is the code.

local function hit(plr, part)
	-- Initialize || Checks
	if not canShoot() then return end
	if not part then return end
	
	-- Get humanoid root part
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	if rootPart then
		-- Check distance
		if(rootPart.CFrame.p - part.CFrame.p).magnitude <- range.Value then -- Check range
			-- Get humanoid
			local humanoid
			
			-- Check if part was a hat/accessory
			if part.Name == "Handle" then
				humanoid = part.Parent:FindFirstChild("Humanoid")
			else
				humanoid = part.Parent:FindFirstChild("Humanoid")
			end
			
			if humanoid and humanoid.Health > 0 then -- Do nothing if humanoid is dead
				local newDamage = damage.Value
				
				-- Check hit
				if part.Name == "Head" then
					newDamage = newDamage * headMultiplier.Value
					
					--Headshot related handling
					local soundCopy = headshotSound:Clone()
					soundCopy.Parent = part
					soundCopy:Play()
				end
				
				--Apply damage
				humanoid:TakeDamage(newDamage)
			end
		end
	end
end

1 comment

0

ScriptingHelpers website guideline: "Attempts should be your own work. Don't take a free model and expect us to fix it.^" Don’t come on to this site with SkeleDotLua’s script.