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
#Freecam teleport command working in studio but not in game
1 messages · Page 1 of 1 (latest)
chatservice?
not textchatservice?
you’re using chatService.OnIncomingMessage = function(message)
which only works in studio, it wont fire in the game
I just made it a variable so its shorter
Whats an alternative for something that works in game the?
player.chatted
is it?
doesn't seem that way to me
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 😭