Hello there! I'm making a game and I need to make a door that is whitelisted so only people over the guest and cadet rank can open and close it. My game is filtering enabled and has to switch back and forth from the client and the server. I learned this month about remote events/remote functions (except I don't know much about remote functions) and tried to use them in this.
But it's not working. I tried to fix it but on line 10 on the open script it gives me this error
Argument 1 missing or nil
Can anyone help me?
Here are the scripts and parts.
Scripts:
Type of script = Script, Name of script = Open:
local CD = script.Parent.ClickDetector local RS = game:GetService("ReplicatedStorage") local RE = RS.RemoteEvents local Debounce = false if script.Parent.ClickDetector.MouseClick then if Debounce == false then Debounce = true RE.DoorAClickCheck:FireClient() wait(0.5) end end RE.DoorAOpen.OnServerEvent:Connect(function() if script.Parent.OpenValue == false then script.Parent.Transparency = 0.5 script.Parent.CanCollide = false end if script.Parent.OpenValue == true then script.Parent.Transparency = 0 script.Parent.CanCollide = true end end)
Type of script = LocalScript, Name of script = LocalOpen:
local CD = script.Parent.ClickDetector local RS = game:GetService("ReplicatedStorage") local RE = RS.RemoteEvents local Player = game.Players.LocalPlayer RE.DoorAClickCheck.OnClientEvent:Connect(function() if Player.leaderstats.Rank == "Guest" or "Cadet" then print("Rejected: Not Over Rank 2") else RE.DoorAOpen:FireServer() end end)
Remote events (These are in replicated storage and are both remote events. {I also have these duplicated but it is DoorB because I'm making another one of these doors.}) : DoorAClickCheck and DoorAOpen
Parts: DoorA
Inside of DoorA: ClickDetector, Open, OpenValue, And LocalOpen
Thanks for reading and or helping me,
Narwhal
You didn't provide a line number where you got the error, but by scanning your script, I assume that it's on line 10. FireClient
(Wiki link) requires at least 1 argument: a player. You should be able to get that reference if you properly use the MouseClick
(Wiki link) event, which also needs to be fixed. I also notice that you never cleared the Debounce
after you enable it on line 9.
Here is my edit to lines 7-12 of your script. It might not fix everything, but it's a start.
script.Parent.ClickDetector.MouseClick:Connect(function(playerWhoClicked) if Debounce == false then Debounce = true RE.DoorAClickCheck:FireClient(playerWhoClicked) wait(0.5) Debounce = false end end)
When you use :FireClient() you need to put the player inside the () example :
FireClient(plr)
you can also put an argument example:
FireClient(plr, "yo")
https://developer.roblox.com/en-us/api-reference/function/RemoteEvent/FireClient
It would become like this:
script.Parent.ClickDetector.MouseClick:Connect(function(plr) if Debounce == false then Debounce = true RE.DoorAClickCheck:FireClient(plr) wait(0.5) end end)
You have to specify the plr
RE.DoorAClickCheck:FireClient(game.Players.UsernameWitheld)
heres it rewritten
local CD = script.Parent.ClickDetector local RS = game:GetService("ReplicatedStorage") local RE = RS.RemoteEvents local Debounce = false script.Parent.ClickDetector.MouseClick(plxr) if Debounce == false then Debounce = true RE.DoorAClickCheck:FireClient(plxr) wait(0.5) Debounce=false end end RE.DoorAOpen.OnServerEvent:Connect(function() if script.Parent.OpenValue == false then script.Parent.Transparency = 0.5 script.Parent.CanCollide = false end if script.Parent.OpenValue == true then script.Parent.Transparency = 0 script.Parent.CanCollide = true end end)