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

Door won't open when button is clicked?

Asked by 3 years ago

I'm making a door that teleports up/down when a button is clicked and making it group rank specific. The error in the output I'm getting is Workspace.Module1.Model.ButtonOpen.Module1Open:8: attempt to index nil with 'GetRankInGroup'

can someone help me figure out what I'm doing wrong?


local Players = game:GetService("Players")                                            
local part = script.Parent                                                                                                                  
local Workspace = game:GetService("Workspace") 
local Door1 = Workspace:WaitForChild("Door1")                                    
local Click = Workspace.Module1.Model.ButtonClose.ClickDetector                                                 

Workspace.Module1.Model.ButtonOpen.ClickDetector.MouseClick:Connect(function(click) 
if Players:FindFirstChild(click.Parent):GetRankInGroup(5339051) > 7 then                           

    Door1:MoveTo(Vector3.new(-38.59, 1, -17.925))
0
Thank you, everyone! I appreciate the answers :) MissDawdle 4 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Hey there! I think your problem is that the script is having trouble detecting who clicked the brick. Try this instead in lines 7-10

Workspace.Module1.Model.ButtonOpen.ClickDetector.MouseClick:Connect(function(plr)
    if plr:GetRankInGroup(5339051) > 7 then
        Door1:MoveTo(Vector3.new(-38.59, 1, -17.925))
    end
end)

If this doesn't work, or if you have any questions, please let me know!

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The MouseClick event returns the player that clicked it, so click.Parent would be the players service, and you're then trying to find the players service inside the players service which it wouldn't be able to find and would return nil (hence the error).

Since it already returns the player that clicked it as shown here, you can just do:

local Open = workspace.Module1.Model.ButtonOpen.ClickDetector

Open.MouseClick:Connect(function(PlayerWhoClicked)
    if PlayerWhoClicked:GetRankInGroup(5339051) > 7 then
        Door1:MoveTo(Vector3.new(-38.59, 1, -17.925))
    end
end)

Answer this question