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

Why cant I get this door work properly?

I am trying to make a door that can only be activated when the key is picked up. The script in the key works fine, but when it is time to click on the door, the doors position doesn't change

Script in Key

local key = script.Parent
local click = key.ClickDetector
local door = game.Workspace.CabinetDoor

local function onClick(clicked)
	key.Transparency = 1
	key.Value.Value = true
end
click.MouseClick:connect(onClick)

Script in Door

local door = script.Parent
local click = door.ClickDetector
local value = game.Workspace.Key.Value.Value
local hidden = game.Workspace.door1

local function onClick(Clicked)
	if value == true then
		door.Position = Vector3.new(33.9, 4.7, 7.6)
		wait(1)
		hidden:Destroy()
	end
end

2 answers

✓ Accepted answer

When you set a variable to a ValueObject's value, it gets that value and the variable doesn't change unless you connect a .Changed event and change it from there.

But you don't have to do that, because you can just check the .Value whenever you need it. Also, you never connect the clickDetector to the function.

local door = script.Parent
local click = door.ClickDetector
local value = game.Workspace.Key.Value
local hidden = game.Workspace.door1

local function onClick(Clicked)
    if value.Value == true then
        door.Position = Vector3.new(33.9, 4.7, 7.6)
        wait(1)
        hidden:Destroy()
    end
end
click.MouseClick:connect(onClick) --// Connect the function.

Hope this helped.

Kind of new to scripting, however I am pretty sure if the key is a tool, it wont allow you to click on something while its selected.

1 comment

0

The key isn't a tool, it is a Part in the workspace

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