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

Change radius to click detector?

i found this door script that opens two doors when the player is near, but how would i go about changing it from seeing if the player is near to just the player clicking a button and the doors opening?

script:

local Open = false
local Radius = 10

function MoveDoors(mod)
	for i = 1, 10 do
		script.Parent.DoorA.Mesh.Scale = script.Parent.DoorA.Mesh.Scale + Vector3.new(-.1 * mod, 0, 0)
		script.Parent.DoorB.Mesh.Scale = script.Parent.DoorB.Mesh.Scale + Vector3.new(-.1 * mod, 0, 0)
		script.Parent.DoorA.Mesh.Offset = script.Parent.DoorA.Mesh.Offset + Vector3.new(.2 * mod, 0, 0)
		script.Parent.DoorB.Mesh.Offset = script.Parent.DoorB.Mesh.Offset + Vector3.new(-.2 * mod, 0, 0)
		wait()
	end
	script.Parent.DoorA.CanCollide = mod == -1
	script.Parent.DoorB.CanCollide = mod == -1
end

while wait(.5) do
	local openning = false
	for _, v in pairs(game.Players:GetPlayers()) do
		if v:DistanceFromCharacter(script.Parent:GetModelCFrame().p) < Radius then
			openning = true 
		end
	end 
	if openning and not Open then
		MoveDoors(1)
		Open = true
	elseif not openning and Open then
		Open = false
		MoveDoors(-1)
	end
end

1 answer

make a model with a door shut and 2 doors that are open its your job to make the button and where it is located name the closed door ClosedDoor name the left open door LeftDoorOpen name the right open door RightDoorOpen add a script (located below) to the button and a click detector to the button group eveything together

local ButtonPart = script.Parent.Parent.ButtonPart
local DoorsShut = script.Parent
local LeftDoorOpen = script.Parent.Parent.LeftDoorOpen
local RightDoorOpen = script.Parent.Parent.RightDoorOpen
local clickdetector = script.Parent.Parent.ButtonPart.ClickDetector

clickdetector.MouseClick:Connect
DoorsShut.Transparency = 1
DoorsShut.CanCollide = false
LeftDoorOpen.Transparency = 0
RightDoorOpen.Transparency = 0
LeftDoorOpen.CanCollide = true
RightDoorOpen.CanCollide = true
wait(1.5)
DoorsShut.Transparency = 0
DoorsShut.CanCollide = true
LeftDoorOpen.Transparency = 1
RightDoorOpen.Transparency = 1
LeftDoorOpen.CanCollide = false
RightDoorOpen.CanCollide = false
end

5 comments

0

I used the script for a reason, it uses the meshes in the parts to resize them, creating a sliding effect, id rather have a smooth sliding door than an instant one

0

ok, i don't know how to do it that way so i put my method! I hope you find the answer your looking for!

0

thanks but im asking how do i rewrite the script i provided so that instead of having the player near the door for it to open, i want it to use a click detector

0

in my opinion, making a new one would be easier, plus do YOU understand what the script is saying?

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