Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Saying message while on part teleportation script not working?

Asked by 6 years ago

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

Log in to vote
0
Answered by
unmiss 337 Moderation Voter
6 years ago

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
Ad

Answer this question