Hello,

I'm making a locked door, which will open if you have collected a key. The door and key are local parts, to make sure it only opens for people who has taken the key using a clickdetector. (The key will also be destroyed when picked up, so the player will know for sure they have it).

These are my current scripts:

Local script in StarterGUI.

local value = false

local KeyDoor = game.Lighting.KeyDoor

  

local function CloneLocalParts()

if value == false then

value = true

KeyDoor:Clone()

KeyDoor.Parent = game.workspace.CurrentCamera

end

end

  

CloneLocalParts()

^ This is for cloning parts from lightning, into the player's camera, making it a local part only they can see.


Normal script inside a model containing the local parts.

local HasKey = false

local key = script.Parent.Key

local DoorLocked = true

local Trigger = script.Parent.Trigger

local DoorPose1 = script.Parent.DoorUnionPos1

  

key.ClickDetector.MouseClick:Connect(function(player)

if HasKey == false then

HasKey = true

key:Destroy()

print("Notification")

DoorLocked = false

end

end)

  

Trigger.Touched:Connect(function()

if HasKey == true then

DoorPose1:Destroy()

end

end)

Everything does work fine for one player as long as it's not local parts. I'm not sure if you can't use clickdetectors in local parts, or if it's something else. Help is very much appreciated if you know what to do!

Thanks, Simon.

4 comments

0

Yes you can. A ClickDetector is not limited to being either server-side or client-side.

0

The normal script inside will not run when you parent the model to the workspace from ReplicatedStorage through a localscript, so you would need to redefine the ClickDetector event again in the localscript.

0

Why are you storing things in Lighting? We have ReplicatedStorage and ServerStorage.

0

Still don't get what I should do to fix the problem, not sure how I should define it, tried a few ways. Don't seem to be working, can someone answer with a block of code I could try?