Hello, I posted about this yesterday and got some assistance but I am once again stuck with my script. I'm more confused than before but I think I am closer to the solution than I was before.
Here is what I want to do:
Player picks up a key from the ground which gives them a tool called "Golden Key" (done) Player touches their key tool to the door which is a part called "GoldenLock" - which then opens the door for only them. (Problems occur here)
Overall, I want 4 tool keys that a player physically holds up to 4 doors layered onto each other, which I plan on unioning individually (as in, 1 door for 1 key) and making them like "chains" for the real door behind them, so as each one disappears, one lock for the door will go away until finally they are allowed to pass through. I would likely layer 4 "locks" on top of each other and using the scripts below, just individually have them become cancollide = false and transparency = 1.
Hopefully this explanation makes sense, I may be rambling a little bit but I just wanted to fully explain my objective here.
Here are my scripts, they are likely very wrong as I am uncertain of how to do a lot of things with remote events...
Local Script, located in StarterPlayer.StarterCharacterScripts
local RemoteEvent = game.ReplicatedStorage.RemoteEvent door = game.Workspace.GoldenLock COOLDOWN_TIME = 1 cooldown = false RemoteEvent.OnClientEvent:Connect(function() local function onTouch(p) if p.Parent.Name == "Golden Key" then if cooldown then return end cooldown = true door.Transparency = 0.5 door.CanCollide = false wait(3) door.Transparency = 0 door.CanCollide = true wait(COOLDOWN_TIME) cooldown = false end end end)
Server Script, located in ServerScriptService
local RemoteEvent = game.ReplicatedStorage.RemoteEvent RemoteEvent.OnServerEvent:Connect(game.Player.userId)
I kept on tinkering with the scripts and every time I thought I figured out the solution, I kept on getting errors and continued to change things until I just kind of came to this mess. I don't even know if this is right, but I think I may be somewhat on the right track.. I don't know if I need to get a unique user for each player that contacts the door, but the way to activate the door is through the key the player is holding. Is this even possible to do for only one client, or is it doomed because the key would technically be server side? Or is it possible because it's a part of the player's individual backpack?
Any assistance I could receive would help immensely, I only completed some scripting lessons from Studio+ about a week ago and had some issues retaining all of the info. I don't want to find a workaround for this so that I may learn from this and become better at scripting. If you have read all of this, thank you very much.
One problem I immediately noticed was that you're not firing the server at all, and even so it's the client you need to fire at, since you're going to open that door only for the one client.
In this case, we'd have to use :FireClient(). I assume the key touches the door in order for it to open, so we'll use a touch event with a debounce so that it doesn't fire your event 100 times.
The script below would likely have to be inside a door.
local db = false script.Parent.Touched:Connect(function(hit) if db == false then db = true local player = game.Players:FindFirstChild(hit.Parent.Name) game.ReplicatedStorage.RemoteEvent:FireClient(player) wait(1) end db = false end)
On your client-side (localscript), you also have to input WHICH client it's directed at, hence why we defined and added "player" as an argument to :FireClient()
RemoteEvent.OnClientEvent:Connect(function()
this line, would likely be replaced with the line below.
RemoteEvent.OnClientEvent:Connect(function(player)
If there are any other issues, let me know.