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)
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
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)
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)
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.