Force to CFrame Not Working

So this script used to make a body force to move the part and I changed the BodyForces Force on line 8 to be blasted in the direction the player hit the part but now I want to change its CFrame to in front of where the part was hit in relation the player that touched it instead (Get the same result but instead of adding a force changing its position) but idk how to change line 8 to properly fit CFrame instead of Force

On line 8 I get: Unable to assign property CFrame. CoordinateFrame expected, got Vector3 (Line 8)

If I remove the .LookVector and beyond part of line 8 it doesn’t error, but it doesn’t go in the right direction also I will later make this tween so it doesn’t just teleport the part but transition there

local part = script.Parent 

part.Touched:Connect(function(hit) 
    if hit.Parent:FindFirstChild("Humanoid") then 
        local hum = hit.Parent:FindFirstChild("Humanoid")
        local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
        local HumanoidRootPart = hit.Parent.HumanoidRootPart -- Line Below ▼
        script.Parent.CFrame = CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector * Vector3.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value) -- This Line Here!
    end -- Line above ↑
end)

use PivotTo because it is a model, but use some if statements so you don’t get some errors

hit.Parent:PivotTo(CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector * Vector3.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value))
1 Like

So now I have this right?:

local part = script.Parent 

part.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local HumanoidRootPart = hit.Parent.HumanoidRootPart
		hit.Parent:PivotTo(CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector * Vector3.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value))
	end
end)

It errors: Unable to cast Vector3 to CoordinateFrame

Also I’m trying to move the part

You are trying to get a lookvector of a vector3, lookvectors are only on cframes, thats why it’s erroing

1 Like

I did this:

local part = script.Parent 

part.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local HumanoidRootPart = hit.Parent.HumanoidRootPart -- Line Below ▼
		script.Parent.CFrame = CFrame.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z,part.Position).LookVector * Vector3.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value) -- This Line Here! 
	end -- Line above ↑
end)

Now I get Invalid number of arguments: 4 (Line 8)

Now I have this (Not sure if this is how you meant either)

script.Parent.CFrame = CFrame.new(HumanoidRootPart.Position.X,HumanoidRootPart.Position.Z,part.Position).LookVector * CFrame.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value)```

Error: invalid argument #1 (CFrame expected, got Vector3) (Line 8)

You need to put in the first argument of cframe.new as a vector, so you need to put Vector3.new around it

1 Like
CFrame.new(Vector3.new(HumanoidRootPart.Position.X,HumanoidRootPart.Position.Z,part.Position).LookVector * CFrame.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value))

Error: LookVector is not a valid member of Vector3 (Line 8)

CFrame.new(Vector3.new(HumanoidRootPart.Position.X, 0, HumanoidRootPart.Position.Z),part.Position).LookVector * CFrame.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value)
1 Like

Also when you set the part’s cframe you have to multiply by current cframe too or it wont be in the right place

1 Like

I appreciate your help! This now says: invalid argument #1 (CFrame expected, got Vector3)

local part = script.Parent 

part.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local HumanoidRootPart = hit.Parent.HumanoidRootPart -- Line Below ▼
		script.Parent.CFrame = CFrame.new(CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector + Vector3.new(300 * plr.HitPower.Value, 20, 300 * plr.HitPower.Value)) -- This Line Here!
	end -- Line above ↑
end)
1 Like

Thank you! this doesn’t error out, but it doesn’t go in the direction I hit it. Do you know why?

Did you want it to go in 300 * HitPower from the LookVector and up 20 studs?

local part = script.Parent 

part.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local HumanoidRootPart = hit.Parent.HumanoidRootPart -- Line Below ▼
		local HumToPart = CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector
		script.Parent.CFrame = CFrame.new((HumToPart * (300 * plr.HitPower.Value)) + Vector3.new(0,20,0)) -- This Line Here!
	end -- Line above ↑
end)

That multiplier used to work correctly on a body force but I’m assuming its very different using CFrames. I want it to go forward a bit and have it so I can multiply it by the Hit Power if that makes sense. its for a hockey puck so I want it to blast in the direction a player hit it and I will turn it into tween I just wanted to figure out how to do this first.

Well, I wouldn’t recommend tweening it since it can’t be stopped by anything it hits. You could try settings it’s Velocity to (LookVector * (300*HitPower)) + Vector3.new(0,20,0).

local part = script.Parent 

part.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local HumanoidRootPart = hit.Parent.HumanoidRootPart -- Line Below ▼
		local HumToPart = CFrame.new(Vector3.new(HumanoidRootPart.Position.X,hit.Position.Y,HumanoidRootPart.Position.Z),part.Position).LookVector
		script.Parent.Velocity = (HumToPart * (300 * plr.HitPower.Value)) + Vector3.new(0,20,0) -- This Line Here!
	end -- Line above ↑
end)

That actually works quite well but my only concern is that I couldn’t use physics because of NetWork Owner lag between Mobile and PC players crossed over.

Hmm… Maybe you could split the visualization from the physics - ie. have a server-owned puck that handles physics, but players don’t see it, and then have a client-owned puck for only for visualization.

One way of doing it would be using the Velocity on both client & server, but destroy the client puck when the server puck has stopped, and then make the server puck visible.

You must choose which way you want to visualize your puck.

1 Like

Ok, thank you for all of your help I really appreciate it! I’ll let you know if it works.