-
What do you want to achieve?
For the object to move smoothly instead of buggy. -
What is the issue?
It doesn’t move smoothly at all.
-
What solutions have you tried so far?
I added the blacklist option but it didn’t work.
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local Towers = ReplicatedStorageService:WaitForChild("Towers")
local TowerToSpawn
local Gui = script.Parent
local Camera = workspace.CurrentCamera
function AddPlaceholderTower(name)
local Tower = Towers:FindFirstChild(name)
if not Tower then
print(name, "doesn't exist!")
return
end
TowerToSpawn = Tower:Clone()
TowerToSpawn.Parent = workspace.Towers
end
function MouseRaycast(blacklist)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = blacklist
local MousePosition = UserInputService:GetMouseLocation()
local MouseRay = Camera:ViewportPointToRay(MousePosition.X, MousePosition.Y)
local RaycastResult = workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000)
return RaycastResult
end
UserInputService.InputBegan:Connect(function(Input, processed)
if processed then return end
end)
RunService.RenderStepped:Connect(function()
if TowerToSpawn then
local Result = MouseRaycast({TowerToSpawn})
if Result and Result.Instance then
local X = Result.Position.X
local Y
local Z = Result.Position.Z
if TowerToSpawn.Humanoid.RigType == Enum.RigType.R15 then
Y = Result.Position.Y + TowerToSpawn.Humanoid.HipHeight + (TowerToSpawn.PrimaryPart.Size.Y / 2)
else
Y = TowerToSpawn:GetExtentsSize().Y / 2
end
local cframe = CFrame.new(X,Y,Z)
TowerToSpawn:SetPrimaryPartCFrame(cframe)
end
end
end)
Gui.Activated:Connect(function()
AddPlaceholderTower(Gui.TowerName.Value)
end)