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

Saying message while on part teleportation script not working?

So I made a script that detects if a player is on a certain part part (game.Workspace.BathroomStuff.Rug) while saying something ("I am me."). If they do that, they get teleported to a part at the coordinates, (-44.2, 2, 69.5). This is all in a local script:

local player = game.Players.LocalPlayer

player.Character.Chatted:connect(function(msg)
    if msg=="I am me." then
                for i,v in pairs(game.Workspace.Bathroom.Rug:GetTouchingParts()) do
                        if v.Parent == player.Character then
                              v.Parent.Torso.CFrame=CFrame.new(-44.2, 2, 69.5)
                                break
                         end
                end
    end
end)

When I tested the script out, there was no error in the output, and I didn't get teleported anywhere. Basically, nothing happened. What did I do wrong?

1 answer

You don't need to use LocalPlayer or a local script with this.

local Players = game:GetService("Players")

for _, player in pairs(Players:GetPlayers()) do
	player.Chatted:connect(function(message)
		if message == "I am me" then
			-- Teleport the player
		end
	end
end

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