ik this is a really simple thing but I’m realising my game today and I need this in my game
basically I want to move an object when the player clicks im not sure if i should use c frame or tween service but i want it to slide
pretty simple just move when the clickdetector is clicked
Use the examples provided on the ClickDetector wiki page to see how to use ClickDetectors in general. If you want gradual movement over time, check out the TweenService wiki page. There are other options for moving Parts , like dmk said you can also manually set the CFrame for example using Lerp (linear interpolation) in a loop.
This code will move the part up by 5 units when the click detector is clicked. You can adjust the movement vector to move the part in a different direction or distance.
local part = script.Parent – the part to be moved
local clickDetector = script.Parent:FindFirstChild(“ClickDetector”) – the click detector
– Function to move the part
local function onClick()
part:MoveTo(part.Position + Vector3.new(0, 5, 0)) – move the part up by 5 units
end
– Connect the click detector’s event to the function
clickDetector.MouseClick:Connect(onClick)