I have a script in which an unanchored item hits a target and then becomes anchored:
for i, v in pairs(game.Workspace.Items:GetChildren()) do
if v.Name == "Shuriken" or v.Name == "Throwing Knife" then
v.PrimaryPart.Touched:Connect(function(hit)
if not v.PrimaryPart:FindFirstChild("IsGrabbed") and hit.Parent.Name == "Target" then
v.PrimaryPart.Anchored = true
end
end)
v.PrimaryPart.ChildAdded:Connect(function(child)
if v.PrimaryPart:WaitForChild("IsGrabbed", 1) then
v.PrimaryPart.Anchored = false
end
end)
end
end
Not exactly sure why that happens, but if you believe the delay is causing an issue, you could try to save the knife’s CFrame at the moment of impact and set the CFrame of the knife back to that after it’s anchored.
I would hazard a guess that the issue here is that your anchoring script is running on the server, but the physics are running on the client.
Hence when the server registers the hit, the knife has already bounced off on the client, causing the delay.
Either use :SetNetworkOwner() on the knife to keep it server side, or use :SetNetworkOwner(Player) on the knife and anchor the knife with a local script
I already have a script handling the Network ownership and changing the knife’s position just caused it to look glitchy when the position was updated
Perhaps you could use some combination of Roblox physics with a hit-scanning (raycasting) method to figure out what part you are aiming at. If the part that the knife hits matches the part detected on the ray, you could use the raycasting information to position the knife embedded in the target properly.
The reason that the result is so egregiously wrong is that there’s an entire network round trip worth of latency involved.
If the part is being simulated by your client here, then not only is does the Touched event get calculated by the client and sent to the server script (one network trip) but then part keeps moving on the client while the Anchored change made by the server script replicates back to the client (second network trip).
It’s definitely NetworkOwnership, had a similar issue as well. Not sure how you’re handling the ownership but if you followed madattak’s instructions properly it should work flawlessly. Anyhow, I recommend using custom projectiles via raycasting for this type of stuff.
Yes it was network ownership, I have just altered my script I had a 2 second delay until network owner ship was set to nil to avoid “choppiness” I’ve worked around this however in my script that deals with network ownership.
I’ve made my script local
I’ve gotten rid of that 2 second delay and instead made it so that the network ownership is set to nil when the part becomes stationary. (This deals with the choppiness and the issue at hand.)