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

How do I do if player ranked 12+ says !open, the door opens?

Asked by 4 years ago

This is what I've made so far:

script.Parent.Transparency = 1
script.Parent.CanCollide = true

-- if player says !open with rank 12+ Group ID: 5370359
script.Parent.Transparency = 0
script.Parent.CanCollide = false 

I just need to know what the code is for "if player says !open with rank 12+ Group ID: 5370359".

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

In order to open a door when the player says "!open", we first need a way to figure out when the player is chatting. To do this, we are going to connect the chatted event every time a player joins. This would look like so:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)

    end)
end)

Ok, now we know that the player chatted, but we don't know what they said. Luckily, the event gives us the message (I made the variable msg but you can change this to whatever you want). Now we just need to check if the first 5 letters of their message says "!open". To do this we can use :sub. Doing so would look like this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg:sub(1, 5) == "!open" or msg:sub(1, 5) == "!Open" then

        end
    end)
end)

Now we are checking if the player is trying to open the door. The final step is to check if their role is 12 or higher. We can do this with :GetRankInGroup, making the final product look like this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg:sub(1, 5) == "!open" or msg:sub(1, 5) == "!Open" then
            if plr:GetRankInGroup(5370359) >= 12 then
                --find the door and change what you need
            end
        end
    end)
end)

That's all there is to it. Hope I helped!

0
^ thank you for spotting that. cmgtotalyawesome 1418 — 4y
0
Thank you for your help! Sloth_WasTaken 41 — 4y
Ad

Answer this question