Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isnt the door opening?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
0
testing. NarwhalAndMe 141 — 5y
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. NarwhalAndMe 141 — 5y
Ad
Log in to vote
1
Answered by
Creacoz 210 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
lol we both wrote at exact same time EmbeddedHorror 299 — 5y
0
epic Creacoz 210 — 5y
0
nvm NarwhalAndMe 141 — 5y
0
ur firing the wrong thing. plr has to be a player not the plr name EmbeddedHorror 299 — 5y
0
ill rewrite it EmbeddedHorror 299 — 5y
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)

0
k testing NarwhalAndMe 141 — 5y
0
btw put ur player not literally game.Players.UsernameWitheld EmbeddedHorror 299 — 5y
0
btw mouseclick takes a parameter of the plr who clicked EmbeddedHorror 299 — 5y
0
^ Creacoz 210 — 5y
View all comments (11 more)
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. NarwhalAndMe 141 — 5y
0
try it now EmbeddedHorror 299 — 5y
0
try it now EmbeddedHorror 299 — 5y
0
try it now EmbeddedHorror 299 — 5y
0
try it now EmbeddedHorror 299 — 5y
0
ugh scripting helpers spams comments if u have bad wifi EmbeddedHorror 299 — 5y
0
ugh scripting helpers spams comments if u have bad wifi EmbeddedHorror 299 — 5y
0
ugh scripting helpers spams comments if u have bad wifi EmbeddedHorror 299 — 5y
0
did it. Didn't quite work though. NarwhalAndMe 141 — 5y
0
how so? any errors? EmbeddedHorror 299 — 5y
0
how so? any errors? EmbeddedHorror 299 — 5y

Answer this question