How can I make a click detector move a part

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

2 Likes

Use tweening if you want an animation when you click and use CFrame if you want to move the part instantly when you click.

2 Likes

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)

3 Likes

thanks for the help everyone
I found a different way to do what I wanted though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.