Unanchored parts on the player's client straight up freezing

I’ve been trying to make a client-sided kicking system for decorative objects that have a specific tag.
(Example: Kickable cups on a table.)

Once the part is touched by the player’s leg, it becomes kicked & body velocity flings it in the player’s direction, it de-spawns after 3 seconds. (This is done through a local script in StarterCharacterScripts.)

The issue with this is that once the part is unanchored, it moves like it’s supposed to for half a second & just completely freezes. What’s weird is that it works fine if it’s unanchored from the start, but if I do that, it’ll be kicking on the server’s side.

I’ve looked around on the Devfourm but I’m still very confused about the issue. I don’t know if it’s the part “sleeping”, if it’s a network ownership thing, or if it’s something completely different.

This is the code that I’m working with at the moment. Any help would be appreciated!

local CollectionService = game:GetService("CollectionService")

--// KICKABLES
for i, KICK in pairs(CollectionService:GetTagged("Kickable")) do
	local event = game.ReplicatedStorage.Events.KickEvent
	local respawnTimer = 3
	local kicked = false
	local debris = game:GetService("Debris")
	local ts = game:GetService("TweenService")
		
	KICK.CollisionGroup = "noPlrs"

	--// THE DESPAWNING
	local function despawnPart(target)
		local fade = ts:Create(target, TweenInfo.new(1), {Transparency = 1})
		task.wait(respawnTimer)
		fade:Play()
		task.wait(1)
		target:Destroy()
	end

	--// THE FUNCTIONING
	local function kick(target)
		local dir = CFrame.lookAt(rp.Position, target.Position).LookVector
		if dir.Magnitude < 0.001 then
			return
		end

		--// this actually kicks it
		local velocity = Instance.new("BodyVelocity")
		velocity.Parent = target
		velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
		velocity.Velocity = dir.Unit * 60 + Vector3.new(0,80,0)

		--// particle
		local attach = Instance.new("Attachment")
		attach.Parent = target

		local particle = game.ReplicatedStorage.FX.Kick
		local clone = particle:Clone()
		clone.Parent = attach
		clone:Emit(1)

		debris:AddItem(velocity, 0.2)
		target.Anchored = false
		print('KICKED:', target)
	end

	local legs = char["Left Leg"] or char["Right Leg"]
	legs.Touched:connect(function(hit)
		if hit == KICK and kicked == false then
			local customSound = KICK:FindFirstChildWhichIsA("Sound")
			if customSound and customSound.Name == "Kick" then
				customSound:Play()
			end
			kick(hit)
			kicked = true
			despawnPart(hit)
		end
	end)
end

You need to assign the network ownership of the part to the player who is kicking it. which can be done by doing “Part:SetNetworkOwner(player)”

1 Like

It almost certainly is a NetworkOwnership problem. You can’t set NetworkOwnership on the client though, so you’re going to have to do it on the server.

1 Like

The way your code is rn you would need to send the target to server through fire server then make the networkowner of the targetObj the player that is kicking, like that it would work normally.

1 Like

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