I’m making a placement system, and when I hover my mouse over a part, it starts making this weird bouncy effect. Almost like pets in simulator games.
This is the code I have:
--// SETTINGS \\--
local lerp = true
local lerp_speed = 0.5
local snap = 1
local max_dist = 50
--// DEFAULTS \\--
local rotation = 0
--// VARIABLES \\--
local WS = game:GetService("Workspace")
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local PS = game:GetService("PhysicsService")
local CHS = game:GetService("ChangeHistoryService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
--// ... \\--
local part = WS.Block:clone()
local canvas = WS.Canvas
local original = {color = part.Color, transparency = part.Transparency}
local round = math.round
part.Parent = game.Workspace
part.Anchored = false
part.Transparency = 0.3
function updateRot()
rotation += 90
end
function updateStatus()
if (part.Position - player.Character.HumanoidRootPart.Position).Magnitude <= max_dist and table.find(WS:GetPartBoundsInBox(part.CFrame, part.Size), canvas) then return true
end
return false
end
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.R then
updateRot()
elseif key.UserInputType == Enum.UserInputType.MouseButton1 then
if (part.Position - player.Character.HumanoidRootPart.Position).Magnitude <= max_dist then
local clone = part:Clone()
clone.CFrame = CFrame.new(round(part.CFrame.X), part.CFrame.Y, round(part.CFrame.Z))
clone.Color = original.color
clone.Transparency = original.transparency
clone.Anchored = true
clone:SetAttribute("Destroyable", true)
clone.Parent = game.Workspace
else
print('Out of bounds')
end
elseif key.UserInputType == Enum.UserInputType.MouseButton2 then
if (part.Position - player.Character.HumanoidRootPart.Position).Magnitude <= max_dist then
local target = mouse.Target
if target:GetAttribute("Destroyable") == true then
target:Destroy()
end
else
print('Out of bounds')
end
end
end)
RS:BindToRenderStep("Movement", Enum.RenderPriority.Input.Value, function()
mouse.TargetFilter = part
part:PivotTo(part.CFrame:Lerp(CFrame.new(round(mouse.Hit.X), mouse.Hit.Y + part.Position.Y/2, round(mouse.Hit.Z))*CFrame.Angles(0, math.rad(rotation), 0), lerp_speed))
part.Color = if updateStatus() then Color3.new(0, 0.30, 0.19) else Color3.new(0.43, 0, 0)
task.wait()
end)