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

Why isnt the door opening?

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

3 answers

✓ Accepted answer

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)

2 comments

0

testing.

0

It worked, but I'm confused why the other bits of code in my scripts arent working. Could you help me with that? You don't have to if you don't want to.

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)

5 comments

0

lol we both wrote at exact same time

0

epic

0

nvm

0

ur firing the wrong thing. plr has to be a player not the plr name

0

ill rewrite it

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)

15 comments

0

k testing

0

btw put ur player not literally game.Players.UsernameWitheld

0

btw mouseclick takes a parameter of the plr who clicked

0

^

0

(It seems you have rewritten it, so imma test that.)Yeah, also i want it to work with anyone, and yet the thing im recoding is in a regular script so I cant say game.Players.LocalPlayer. I think thats how that works.

0

try it now

0

try it now

0

try it now

0

try it now

0

ugh scripting helpers spams comments if u have bad wifi

0

ugh scripting helpers spams comments if u have bad wifi

0

ugh scripting helpers spams comments if u have bad wifi

0

did it. Didn't quite work though.

0

how so? any errors?

0

how so? any errors?

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