Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you use clickdetector to make an interactive window?

I was wondering how to use click detector to make an openable window. I've only seen tutorials for doors but not windows..

1 comment

0

DISCLAIMER: I am asking for the basics that I can use not requesting someone to make it for me.

1 answer

✓ Accepted answer

To make such a script, I would suggest splitting it into multiple different sections (decomposition) to solve before actually attempting it.

1: Detection - How do you detect when a person clicks a window

2: Movement - How do you move the object into the desired position.

For detection, you appear to understand that the most useful tool is clickdetector, I would also use such a feature, using ClickDetector.MouseClick to connect to a function.

For the movement part, I would suggest either one of the following two:

  • Tweenservice: More complicated to implement, and if moved requires different position data to be used, however allows for more complicated movement such as easingstyle and easingdirection
  • Editing CFrame inside of for loops, which is easier, and can be moved to any location and still operatate efficiently.

Personally, for this task, I would use CFrame loop, as it's not really an operation that would need such complex movement that tweenservice provides. Here is a example script for a hangar door I have:

local moving


local originalLeft = script.Parent.Left.PrimaryPart.CFrame
local originalRight = script.Parent.Right.PrimaryPart.CFrame


function move()
	for i=1,180 do
		script.Parent.Left:SetPrimaryPartCFrame(originalLeft * CFrame.new(-9.2*(i/60),0,0))
		script.Parent.Right:SetPrimaryPartCFrame(originalRight * CFrame.new(9.6*(i/60),0,0))
		wait()
	end
	
	wait(5)
	script.Parent.Collision.Touched:Wait()
	wait(4)
	
	for i=177,0,-1 do
		script.Parent.Left:SetPrimaryPartCFrame(originalLeft * CFrame.new(-9.2*(i/60),0,0))
		script.Parent.Right:SetPrimaryPartCFrame(originalRight * CFrame.new(9.6*(i/60),0,0))
		wait()
	end
	
	wait(1)
end




script.Parent.Collision.Touched:connect(function(hit)
	if not moving then
		moving = true
		move()
		moving = false
	end
end)

Hope this answers your question. :)

1 comment

1

Thank you so much! This answers my question and helps me a lot. Now I can use this knowledge and put it to use for my window.

This discussion is preserved as it was. New answers, comments, and votes are closed.