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

How to make if Player is in group and player chatted then?

I have a local script so if the Player is in the group and the player also chatted a certain keyword then it does something, I am in the group but it still doesn't work ;c, Can you help me?

local player = game.Players.LocalPlayer

Player.Chatted:connect(function(msg)

local groupId = 2723362

if player:IsInGroup(groupId) and player:GetRoleInGroup(groupId) >= "GM's Assistant" and
	
	string.sub(msg,1,5) == "tron/SD" then
	
	game.Tron.Decal.Transparency = 1
	
end
	

Tron is the Part that the Decal is on, Whenever I say tron/SD it does nothing, Idk if there is a error or not that I cannot see,

Here is a second code that still didn't work ;c

local Player = game.Players.LocalPlayer

Player.Chatted:connect(function(msg)

local groupId = 2723362

if Player:IsInGroup(groupId) and Player:GetRoleInGroup(groupId) >= "GM's Assistant" and
	
	string.sub(msg,1,5) == "tron/SD" then
	
	game.Tron.Decal.Transparency = 1
	
end
end)


1 answer

✓ Accepted answer

The problem here is that you are trying to see if a string is bigger than another:

Player:GetRoleInGroup(groupId) >= "GM's Assistant"

I take it from the 3rd condition in that if statement that you know the difference between >= and ==, so I've assumed that you are attempting to make players with a rank higher or equal to GM's Assistant have permissions to use the command.

But, like I said, you cannot compare strings using mathematical conditions. :GetRankInGroup() returns a rank id up to 255, which is the owner's rank. Simply find the rank id of GM's Assistant, and problem solved!

I have also added in a few optimisations to make your code work the best it can!

local minRank = 255 -- GM's Assistant rank
local groupId = 2723362

-------------------------------------

local p = game.Players.LocalPlayer
-- I checked things at the start of the code, not inside the chatted event, because it only needs to run once
if p:GetRankInGroup(groupId) >= minRank then -- IsInGroup is pointless, since people not in the group would be rank 0
	p.Chatted:connect(function(msg)
		if string.sub(msg,1,5) == "tron/SD" then
			-- code
		end
	end)
end

Hope I helped!

~TDP

4 comments

0

Didn't work, But I do have this in the logs I am curious about, What is Plugin_184275443.Manager:28: attempt to concatenate local 'newVersion' (a nil value)

0

A ROBLOX error - I don't know what it is. As for my answer, did it send an error? I assure you that my code works. Make sure to set up some prints to test where it goes to, and edit 'minRank' to your preference.

0

I was told that it should be (msg,1,7) == "tron/SD" but that still doesn't work, It shows no errors though so I am guessing there is something wrong on my end

0

Use prints to debug lol

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