Weird position replication

Hello! I made a Harry Potter wand system, and one of the spells I’ll be showing anchors the character and makes them turn into stone.

It appears that when the script anchors the player’s character, if the player is not moving, they’ll be anchored correctly, and the raycast will find the character, but if the player is moving/jumping, the spell will anchor them to their last position and the raycast won’t be able to track it

I have tried setting the player’s ownership to the server and to the player again, unsuccessfully. The most accurate result I’ve achieved was when I set the player’s speed and jump power to 0, but that’s not the effect I desire.

here’s a gif of what happens:
https://gyazo.com/94578e1ecad0c00eb6cca4e686ec940f

Here is my script:

 local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if plr and char.Head.Material == Enum.Material.Plastic  then
	local accessoriesTable = shared.characterAccessories[plr.Name]
	local basepartsMaterials = {}
	local basepartColors = shared.characterBodyColors[plr.Name]
		for i, v in ipairs(char:GetDescendants()) do
		if (v:IsA("BasePart") or v:IsA("WedgePart") or v:IsA("UnionOperation") or (v:IsA("MeshPart") and  not v.Parent:IsA("Accessory"))) and v.Name ~= "HumanoidRootPart" and v.Parent.Name ~= "Wand" then
			table.insert(basepartsMaterials, v.Material)
		end
	end
	for i, v in ipairs(char:GetDescendants()) do
		if (v:IsA("BasePart")) and v.Name ~= "HumanoidRootPart" and v.Parent.Name ~= "Wand" then
			v.Anchored = true
			v.Material = Enum.Material.Slate
			v.BrickColor = BrickColor.new("Fossil")
		end
		if v:IsA("Shirt") or v:IsA("ShirtGraphic") or v:IsA("Pants") then
			v.Parent = script.Additional.Clothes
		end
		if (v.Parent:IsA("Accessory")) and v:IsA("MeshPart") then
			v.TextureID = ""
		elseif (v.Parent:IsA("Accessory")) and v.Name == "Handle" and not v:IsA("MeshPart") then
			if v:FindFirstChild("Mesh") then
				v.Mesh.TextureId = ""
			elseif v:FindFirstChild("SpecialMesh") then
				v.SpecialMesh.TextureId = ""
			end
		end
		if v.Name == "HumanoidRootPart" and v:IsA("BasePart") then
			v.Anchored = true
		end
	end
	wait(3)
	for i, v in ipairs(char:GetDescendants()) do
		if (v.Parent:IsA("Accessory")) and v:IsA("MeshPart") then
			v.BrickColor = BrickColor.new("Medium stone grey")
			v.Anchored = false
			v.Material = Enum.Material.Plastic
			v.TextureID = accessoriesTable[v.Parent.Name]
		end
		if (v.Parent:IsA("Accessory")) and v.Name == "Handle" and not v:IsA("MeshPart") then
			v.BrickColor = BrickColor.new("Medium stone grey")
			v.Anchored = false
			v.Material = Enum.Material.Plastic
			if v:FindFirstChild("Mesh") then
				v.Mesh.TextureId = accessoriesTable[v.Parent.Name]
			elseif v:FindFirstChild("SpecialMesh") then
				v.SpecialMesh.TextureId = accessoriesTable[v.Parent.Name]
			end
		end
		if (v:IsA("BasePart")) and not v.Parent:IsA("Accessory") and v.Name ~= "HumanoidRootPart" and v.Parent.Name ~= "Wand" then
			v.Anchored = false
			v.Material = basepartsMaterials[1]
			v.Color = basepartColors[v.Name]
		end
		if v:IsA("Shirt") or v:IsA("ShirtGraphic") or v:IsA("Pants") then
			v.Parent = char
		end
		if v.Name == "HumanoidRootPart" and v:IsA("BasePart") then
			v.Anchored = false
		end
	end
end
-----------
wait()
script:Destroy(

If you have any suggestions on how to fix this issue or an alternative to it please let me know! Thank you for reading :smiley:

2 Likes

wow this is very cool how do i make wands like that

Thank you for your feedback but please stay on topic, if you have any suggestions on how to help me with the issue let me know

1 Like

maybe try with a loop:

while RaycastResult ~= nil do
   Damage(...)
   break
end

my best guess would be that it’s not registering the hit because of the delay thing, so if you loop till it’s registered it may fix the issue. I recommend doing the hit detection on the client and add sanity checks for both client/server