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))
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!
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)