Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

3 comments

0

^ thank you for spotting that.

0

Thank you for your help!

This discussion is preserved as it was. New answers, comments, and votes are closed.