I am trying to make it so that you can place an NPC. It all works percectly, except where it is placed. The excact location is correct, but where the NPC is placed is wrong. PLEASE help me I am desperate. I asked several times with no response.
CODE:
local function place()
print("func fired")
local newTower = tower:Clone()
local bubble = newTower.Bubble
local range = newTower.Settings.Range.Value
local account = 16
bubble.Size = Vector3.new(0.5, range + account, range + account)
bubble.Transparency = 0.6
bubble.Material = Enum.Material.Neon
local yOrientation = 0
local canPlace = false
if not placing then
placing = true
newTower.Parent = workspace
game:GetService("RunService").RenderStepped:Connect(function()
if newTower and placing then
local mouseRay = mouse.UnitRay
local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000000000)
local ignoreList = newTower:GetChildren()
table.insert(ignoreList, #ignoreList, root.Parent)
local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)
if hit then
if hit.Name == "Grass" and hit.Parent.Name == "FloorTowers" then
canPlace = true
bubble.Color = Color3.fromRGB(0, 160, 255)
else
canPlace = false
bubble.Color = Color3.fromRGB(255, 0, 0)
end
if newTower:FindFirstChild("Bubble") then
newTower.Bubble.Transparency = 0.6
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local newCFrame = CFrame.new(position.X, position.Y + yOffset, position.Z)
if newTower then
if newTower.PrimaryPart then
newTower.PrimaryPart.CFrame = newCFrame * newCFrame
end
end
end
end
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyDown = true
local speed = 2.5
while rKeyDown do
yOrientation = yOrientation + speed
tower.PrimaryPart.Orientation = Vector3.new(0, yOrientation, 0)
wait()
end
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyDown = false
end
end)
mouse.Button1Down:Connect(function()
if placing then
if canPlace and newTower then
game.ReplicatedStorage.Remotes.PlaceTower:FireServer(tower, newTower.PrimaryPart.CFrame)
game.ReplicatedStorage.Remotes.PlaceTower.OnClientEvent:Wait()
newTower:Destroy()
placing = false
end
end
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Z then
placing = false
newTower:Destroy()
end
end)
end
end
TYSM!

7 comments
Instead of setting the actual parts cframe as the towers cframe when you fire the remote, keep a local variable that uses the same CFrames as what you set the temporary tower's cframe as. If its the way you want prior to placing it, then I would send those CFrame cords to the server, not the temporary towers cframe.
e.g: game.ReplicatedStorage.Remotes.PlaceTower:FireServer(newCFrame * newCFrame)
I don't know what you mean
Okay I got the remote event, and I realize how that is better, but I don't understand the other part. Please elaborate. Thanks for your help btw! :D
also ninja I did what you said and it still didn't fix it. the tower is still ofset
I posted an answer, I don't know if it'll fix it our not. I have a few errands to run IRL and I'll check back after and see if we can get a solution if it doesnt work.
kk