Staff Door not working

Hello, I was creating a staff door but seems like my scripts doesn’t works, can someone help?

Thanks for reading :smile:

Maybe send the scripts here so we see what doesn’t work.

This should help you: Player | Documentation - Roblox Creator Hub

Use the :GetRankInGroup(GroupId) API and then compare the value with the rank values in your group.

What is your script? Please send it so I can help.

Hey, this is my script.

–Settings
GroupID = 6541198 --Insert the group ID here
Rank = 229 --Insert the staff+ rank(Number)
NonRank = 227

–THE SCRIPT

local h

script.Parent.Touched:connect(function(Part)
h = Part.Parent:FindFirstChild(“Humanoid”)
if Part.Parent:FindFirstChild(“Humanoid”) then
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player:GetRankInGroup(GroupID) >= Rank then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
wait(0.5)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
elseif Player:GetRankInGroup(GroupID) <= Rank then
if h ~= nil then
h.Health = 0
end
end
end
end)

Please put your code between three backticks like this:
```
–Code here
```
It makes the code easier to read.

Here is formatted version:

GroupID = 6541198 --Insert the group ID here
Rank = 229 --Insert the staff+ rank(Number)
NonRank = 227

local h

script.Parent.Touched:connect(function(Part)
    h = Part.Parent:FindFirstChild(“Humanoid”)
    if Part.Parent:FindFirstChild(“Humanoid”) then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
            if Player:GetRankInGroup(GroupID) >= Rank then
                script.Parent.Transparency = 1
                script.Parent.CanCollide = false
                wait(0.5)
                script.Parent.Transparency = 0
                script.Parent.CanCollide = true
            elseif Player:GetRankInGroup(GroupID) <= Rank then
                if h ~= nil then
                    h.Health = 0
                end
           end
    end
end)

Now, what isn’t working in the script?

Please put your code in a lua code block.

Also, what in the name of alvin aley is this? Can you explain how it works?

Why is there just a declared variable that isnt assigned to anything?

“local h”

I think you need something at the variable h like airsoft said, I don’t know what should be as script in the variable but I am pretty sure its the variable which is the problem.

GroupID = 6541198 --Insert the group ID here
Rank = 229 --Insert the staff+ rank(Number)
NonRank = 227

local h

script.Parent.Touched:connect(function(Part)
    h = Part.Parent:FindFirstChild(“Humanoid”)
    if h then
        local Player = game.Players:GetPlayerFromCharacter(h.Parent)
            if Player:GetRankInGroup(GroupID) >= Rank then
                script.Parent.Transparency = 1
                script.Parent.CanCollide = false
                wait(0.5)
                script.Parent.Transparency = 0
                script.Parent.CanCollide = true
            elseif Player:GetRankInGroup(GroupID) <= Rank then
                if h ~= nil then
                    h.Health = 0
                end
           end
    end
end)

Nothing looks wrong with this script, it should work. Are there any errors?

You can have a variable that isnt defined and it an still be defined later on. Ill give 2 examples.

function something()
    local a = true
    return false
end

the variable will return false, as it was called in the script. here’s a clearer example:

local int -- nothing assigned
int = 20 -- new value

so now int = 20

Didn’t I already say this like 7 minutes ago…

Solved!---------------------…

1 Like

I said it so he can understand it. hence the explanation, since i was assuming that he didn’t know what undefined variables were

1 Like

Ah right. Forgot bout that. Thanks for the reminder.

1 Like