Dumb client server replication with hitbox module

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    the knife actually landing where its supposed to on the client and server

  2. What is the issue? Include screenshots / videos if possible!
    the knifes landing position dosent land correctly on the client

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive tried using the normal .touched, setting the networkowner to nil and player, using entered touched from the module, and etc.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

the servercode for the knife:

local tool = script.Parent
local KnifeSpeed = 1

script.Parent.Communicate.OnServerEvent:Connect(function(plr, request, mouseCF)
	local char = tool.Parent
	if plr == game.Players:GetPlayerFromCharacter(char) then
		local hum = char:FindFirstChildOfClass("Humanoid")
		if request == "Held" then
			local DebugPart = Instance.new("Part",workspace)
			DebugPart.CFrame = mouseCF
			DebugPart.Size = Vector3.new(1,1,1)
			DebugPart.Anchored = true
			DebugPart.Material = Enum.Material.Neon
			DebugPart.Color = Color3.new(1,0,0)

			local knifemodel = script.Parent.Handle.Knife:Clone()
			knifemodel.Name = (plr.Name.."'s thrown knife")
			knifemodel.Parent = workspace
			knifemodel.WeldConstraint:Destroy()
			knifemodel.CFrame = CFrame.new(knifemodel.Position,mouseCF.Position)
			local dir = (mouseCF.Position - knifemodel.Position).Unit * KnifeSpeed * 100
			local Vel = Instance.new("BodyVelocity",knifemodel)
			Vel.Velocity = dir 
			local att = Instance.new("Attachment",knifemodel)
			local AngVel = Instance.new("AngularVelocity",knifemodel)
			AngVel.AngularVelocity = Vector3.new(-10 * KnifeSpeed,00,0)
			AngVel.MaxTorque = math.huge
			AngVel.Attachment0 = att
			AngVel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
			knifemodel:SetNetworkOwner(nil)
			knifemodel.StabBox:SetNetworkOwner(nil)

			local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
			local Params = OverlapParams.new()
			Params.FilterType = Enum.RaycastFilterType.Exclude
			Params.FilterDescendantsInstances = {knifemodel}
			local Hitbox = HitboxModule:CreateWithPart(knifemodel.StabBox, Params)

			Hitbox:Start()
			local Items = Hitbox:GetItems()
Hitbox.Entered:Connect(function(hit)
				if hit.Parent:IsDescendantOf(script.Parent.Parent) == true or hit.Parent == char then
					return
				end
				print(hit:GetFullName())
				knifemodel.Anchored = true
				task.wait()
				knifemodel.CFrame = knifemodel.CFrame
end)




		end
	end
end)

the module in question thats being used:

(keep in mind that this still applies when using default roblox functions, not just the module.)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

The knife is contacting the floor before it reaches the set point and that causes the hitbox module to fire your handler that anchors it early. You may want to implement a raycast inside the handler that checks if the knife’s direction is impeded by the hit object and only stop if it’s not a damageable character.

the knifes position isnt exactly what im worried about, its the fact that the client and the server see different things in the knifes cframe

If the client is providing the CFrame of the spot their mouse is at, I don’t see how the server is seeing a different view. Is the debug part not showing up where you expect?

the debug part is exactly where its supposed to be, but if yop watch the video, you can see what i mean, the client sees the knifes landing position in a different spot then the server

The server anchors the knife once it touches something. Unless you have another script on the client that’s doing its own logic on the knife’s position, then that spot is where the knife is on both the server and client view. The destination spot is correct, the knife just touches the floor earlier and the server locks it into place.

knifemodel.CFrame = knifemodel.CFrame

Is this line supposed to set the knife to be the final destination?

thats a debug line, trying to get it to set, the issue is that it lands exactly where its supposed to on the server, but the client anchors the knife object before it lands, probably due to server to client replication latency

If you could, please try this out: add a second debug part that’s placed at the knifemodel’s CFrame inside the hitbox handler.

well, i found another compromise, just turning the velocity of the angular and body velocitys to 0 has the same desired affect, but its definitley strange how that works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.