Textchatcommand doesn't trigger from an if statement

I’m trying to make some admin commands, because who doesn’t love abusing admin in your own game?

anyway, the entire function works, but the if statement doesn’t seem to run

local TCS = game:GetService("TextChatService")
local SS = game:GetService("ServerStorage")
local Players = game:GetService("Players")

-- // COMMANDS
local DummyPFCommand = TCS:WaitForChild("SpawnDummyPF")





-- // EXECUTION

DummyPFCommand.Triggered:Connect(function(source, message)
	local admin = Players:GetPlayerByUserId(source.UserId)
	local Enemies = SS:WaitForChild("Enemies")
	
	if admin == 473208961 then -- this is the same as if TextSource.UserId == right???
		print("triggered!") -- this doesn't print :(
		local DummyPF = Enemies:WaitForChild("DummyPF"):Clone()
		
		DummyPF.Parent = workspace
		DummyPF:FindFirstChild("HumanoidRootPart").CFrame = admin:FindFirstChild("HumanoidRootPart").CFrame + CFrame.new(0,0,-3)
	end
end)

GetPlayerByUserId returns the player from a UserId.

In the if statement, you are checking to see if admin (which is the player instance that you got) is a number.

I think what you are trying to go for is:

if source.UserId = 473208961 then
1 Like

GetPlayerByUserId gives you the player object that is associated with that UserId, provided they’re in the game.

Just change this:

local admin = Players:GetPlayerByUserId(source.UserId)
local Enemies = SS:WaitForChild("Enemies")
	
if admin == 473208961 then

to this:

if source.UserId == 473208961 then
1 Like

oh. my. god.

i’m never programming again

this is the simplest fix i’ve ever seen

3 Likes