#Freecam teleport command working in studio but not in game

1 messages · Page 1 of 1 (latest)

gleaming swan
#
    if message.TextSource then -- Check if there's a textSource
        local speaker = Players:GetPlayerByUserId(message.TextSource.UserId)
        if speaker == Players.LocalPlayer then -- If the source is the PLAYER
            local txt = message.Text
            print("Detected message:", txt)

            if role == "Spectator" then -- If the player is a spectator
                if txt:sub(1, 4) == "/tp " then -- Tp command trigger 
                    local target
                    
                    for _, i in ipairs (workspace:GetChildren()) do
                        if i.Name == txt:sub(5) and i:IsA("Model") and Players:GetPlayerFromCharacter(i) then
                            target = i -- search for the PLAYER CHARACTER as there's a part in the game named after players
                            break
                        end
                    end
                    
                    if target and Players:GetPlayerFromCharacter(target) then -- Make sure it's a player and not some random part
                        local tpRoot = target:FindFirstChild("HumanoidRootPart")
                        if tpRoot then
                            cam.CameraType = Enum.CameraType.Scriptable
                            cam.CFrame = tpRoot.CFrame -- teleport the camera to a player's torso
                            disableFreecam:FireServer() -- Disable for roblox freecam
                            task.wait(0.1)
                            enableFreecam:FireServer() -- Enable shortly after
                        end
                    end
                end
            end
        end
    end
end```

I'm making a text chat command (/tp [name]) for spectators to teleport to players in the game. The weird thing is that it works in studio, but not in game... What are some reasons for that? Can someone help me out here
lost apex
#

not textchatservice?

young flicker
#

you’re using chatService.OnIncomingMessage = function(message)

which only works in studio, it wont fire in the game

gleaming swan
gleaming swan
gleaming swan
#

I thought it was depreciated

#

Maybe im just insane

#

😭

lost apex
#

is it?

gleaming swan
#

I thought it was cause it wasnt working

#

i’ll try it again JUST to make sure

lost apex
#

doesn't seem that way to me

gleaming swan
#

Cause i mightve just been tripping when I tried it

#

ok yeah I mustve made a mistake when I did it then

#

Alr ty!!

#

So I tried out the chatted event but it doesn't even fire 😭

cold warren
#

Trtyto print plr

#

Also loop trough the game.Players:GetPlayers to reduce buggs

#

Try to handle the chat part in the server

#

@gleaming swan

gleaming swan
#

nevermind I got it

#

Im just ed and used it in a local script