Hello,
I am making a tower defense game. I am trying to make the tower but I need some help. The tower is not following the mouse like it supposed to. Idk why it happens. I have a test button and after I press it. This happened:

Here are the script:
local function raycast(blacklist)
local mousePosition = UserInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
local raycastParams= RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = blacklist
local result = workspace:Raycast(mouseRay.Origin,mouseRay.Direction * 100,raycastParams)
end
local function removePlaceholder()
if placeholder then
placeholder:Destroy()
placeholder = nil
end
end
local function addPlaceholder(name)
-- remove previous placeholder
removePlaceholder()
-- add placeholder
local towerExists = ReplicatedStorage.Tower:FindFirstChild(name)
if towerExists then
placeholder = towerExists:Clone()
placeholder.Parent = camera
end
end
gameGui.Test.Activated:Connect(function()
addPlaceholder(gameGui.Test.Text)
end)
RunService.RenderStepped:Connect(function()
-- control mouse
if placeholder then
-- raycasting
local result = raycast({placeholder})
if result and result.Instance then
local x = result.Position.X
local y = result.Position.Y -- the height offset
local z = result.Position.Z
local cframe = CFrame.new(x,y,z)
placeholder:SetPrimaryPartCFrame(cframe)
end
end
end)
please tell me what I did wrong. Ty