DragDetector Help

how to make when i press run or play the game the lever will be on the top currently its down

local ScriptFolder = script.Parent
local SwitchModel = ScriptFolder.Parent

local Switch = SwitchModel.Switch
local SwitchDrag = Switch.DragDetector

local HingePart = SwitchModel.Hinge
local HingeConstraint = HingePart.HingeConstraint

Switch:SetAttribute("isOn", false)

local State = Switch:GetAttribute("isOn")

local WeldConstraint = HingePart.WeldConstraint

SwitchDrag.DragStart:Connect(function()
	WeldConstraint.Enabled = false
	State = Switch:GetAttribute("isOn")
end)

SwitchDrag.DragEnd:Connect(function()
	WeldConstraint.Enabled = true
end)

SwitchDrag.DragContinue:Connect(function()
	local angle = HingeConstraint.CurrentAngle
	
	if angle >= 65 or angle <= -65 then
		if State == (angle > 0) then
			Switch:SetAttribute("isOn", angle < 0)
			WeldConstraint.Enabled = true
			SwitchDrag.Enabled = true
			
			task.delay(1, function()
				SwitchDrag.Enabled = true
			end)
		end
	end
end)

image

Based on the information you’ve given, this shouldn’t be a drag detector problem. If you put the switch in an upright position before starting a playtest, it should start in an upright position.

Another potential problem that I did notice is that you’re using a weld constraint to hold it in place. If that isn’t enabled at the beginning, I can imagine the handle flipping down due to gravity. Check that before starting another playtest.

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