Struggling with hitbox detection on the client

I’m trying to make hitbox detection on the client because I am using projectiles that are being tweened and are having velocities applied to them.

Example
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local HttpService = game:GetService('HttpService')

local Assets = ReplicatedStorage.Assets
local Sounds = Assets.Sounds
local Remotes = ReplicatedStorage.Remotes

local Meteor = {}

function Meteor:Init()
	Remotes.ToClient.OnClientEvent:Connect(function(signal,ray,pos,resPos,impactSize,meteorSizeMultiplier,impactName)
		if signal == "Meteor" then
			local meteor = Assets.Meteor:Clone()
			local sfx_wind = Sounds.Meteor.Wind:Clone()
			local sfx_impact = Sounds.Meteor.Impact:Clone()
			local impact = meteor.Impact
			local rock = meteor.Rock
			local fire = rock.Attachment.ParticleEmitter
			local ray = ray
			local originP = pos
			local targetP = resPos
			local touched = false
			local c

			sfx_wind:Play()
			sfx_wind.Parent = rock
			sfx_impact.Parent = impact
			
			rock.Size *= meteorSizeMultiplier
			impact.Size *= meteorSizeMultiplier
			
			meteor.Parent = workspace
			meteor:MoveTo(originP)
			
			impact.Name = impactName
			impact.Parent = workspace
			impact.Touched:Connect(function(hit)
				local character = hit.Parent
				local humanoid = character:FindFirstChild("Humanoid")
				if humanoid and not touched then
					touched = true
					print("Touched")
					Remotes.ToServer:FireServer("Hitbox",humanoid,impactName)
				end
			end)

			local moveRock = TweenService:Create(rock,TweenInfo.new(0.75,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Position = targetP + Vector3.new(0,rock.Size.Y/2,0)})

			c = RunService.Heartbeat:Connect(function()
				impact.Position = rock.Position
			end)

			moveRock:Play()
			moveRock.Completed:Connect(function()
				rock:Destroy()
				c:Disconnect()
				impact.Anchored = true
				local impactBurst = TweenService:Create(impact,TweenInfo.new(0.75,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out),{Size = impact.Size + Vector3.one * 10})
				impactBurst:Play()
				sfx_impact:Play()
				impactBurst.Completed:Connect(function()
					impact:Destroy()
					meteor:Destroy()
				end)
			end)
		end
	end)
end

return Meteor

There is a touched event in the example above showing that I am trying to send over the partName I am setting on the client which is (HttpService:GenerateGUID()). The problem is, nothing on the client appears on the server.

I could use position to validate the player’s distance between the impact part and their root. The problem though, is that this is highly exploitable as someone can just change the position to make it hit another humanoid.

Hitboxes
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage.Remotes

local Hitboxes = {}

function Hitboxes:Init()
	print("Initalized")
	Remotes.ToServer.OnServerEvent:Connect(function(player,signal,humanoid,partName)
		if signal == "Hitbox" then
			local impact = workspace:FindFirstChild(partName)
			print(impact)
			local root = humanoid.Parent:FindFirstChild("HumanoidRootPart")
			if root and (impact.Position - root.Position).Magnitude < math.max(partName.Size.X,partName.Size.Y,partName.Size.Z) * 1.1 then
				print("Damaged")
				humanoid:TakeDamage(impact:GetAttribute("Damage"))
			end
		end
	end)
end

return Hitboxes

I need to send the part to the server to get the damage attribute and also validate its size.

Both options are double-edged swords and in several ways they both don’t work.

1 Like

I tried creating the meteor projectile on the client but I realized, the client has no network ownership over the meteor now.

1 Like