LookVector has a "1 click" delay

Hey! I was messing around with prop spawning when I noticed that each time I click, the prop spawns fine but it spawns at my old HRP LookVector position until I click again, then it spawns at my current HRP LookVector position.

Here’s a video to help you understand a bit more…

Here are the 2 scripts that allow the prop spawning to happen:

LocalScript:

prop.MouseButton1Click:Connect(function()
	local pos = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * 5
	local toCFrame = CFrame.new(pos)
	
	SpawnProp:FireServer(prop.Name, toCFrame)
end)

ServerScript:

SpawnProp.OnServerEvent:Connect(function(player, prop, pos)
	if Props:FindFirstChild(prop) then
		local propToSpawn = Props:FindFirstChild(prop)
		
		propToSpawn:Clone().Parent = workspace
		
		if propToSpawn:IsA("Model") then
			propToSpawn:SetPrimaryPartCFrame(pos)
		else
			propToSpawn.Position = pos
		end
	end
end)

Not quite sure what is wrong with the scripts…

Any help is appreciated, thank you in advance!

It seems that the problem is in your Script. You’re setting the Position/CFrame of the original prop object after spawning the clone, not the clone’s. So, when you duplicate the object and parent that cloned object to the workspace, it’s spawning where the original prop was before its Position/CFrame got updated.

I recommend setting the cloned prop’s Position/CFrame instead. Though, you can also just set the original prop’s before you clone it and spawn that duplicate, which means this would go before propToSpawn:Clone().Parent = workspace:

if propToSpawn:IsA("Model") then
    propToSpawn:SetPrimaryPartCFrame(pos)
else
    propToSpawn.Position = pos
end
1 Like

Ohh it makes so much more sense now that I re-read the code. Thank you!

1 Like

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