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

How do I make the script detect the chat?

Asked by 4 years ago
Edited 4 years ago

This sounds like a stupid question but it's not.

I'm making a simulator with a pet equip system with chat and for some reason it does not detect the chat when it used to.

This is the local script:

local peton = false
local player = game.Players.LocalPlayer
player.Chatted:Connect(function(chat)
    if chat == "/petequip" then
        peton = true
        game.StarterGui:SetCore("ChatMakeSystemMessage",{
            Text = "Now say the pet you want to equip. Make sure to captialize the first letter!";
            Color = Color3.new(1, 1, 1);
            Font = Enum.Font.Arcade;
        })
        player.Chatted:Connect(function(chat)
            if peton == true then
                peton = false
                local id = "0"
                if chat == "Doggo" then
                    id = "1"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                else
                    if chat == "Kitty" then
                        id = "2"
                        game.Workspace.PetEquip.Remote:FireServer(id)
                    else
                        if chat == "Bunny" then
                            id = "3"
                            game.Workspace.PetEquip.Remote:FireServer(id)
                        else
                            if chat == "Beary" then
                                id = "4"
                                game.Workspace.PetEquip.Remote:FireServer(id)
                            else
                                if chat == "Birdy" then
                                    id = "5"
                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                else
                                    if chat == "Neon Orb" then
                                        id = "6"
                                        game.Workspace.PetEquip.Remote:FireServer(id)
                                    else
                                        if chat == "Neon Chaos Elemental" then
                                            id = "7"
                                            game.Workspace.PetEquip.Remote:FireServer(id)
                                        else
                                            if chat == "Stone" then
                                                id = "8"
                                                game.Workspace.PetEquip.Remote:FireServer(id)
                                            else
                                                if chat == "Coal" then
                                                    id = "9"
                                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                                else
                                                    if chat == "Iron" then
                                                        id = "10"
                                                        game.Workspace.PetEquip.Remote:FireServer(id)
                                                    else
                                                        if chat == "Amethyst" then
                                                            id = "11"
                                                            game.Workspace.PetEquip.Remote:FireServer(id)
                                                        else
                                                            if chat == "Sapphire" then
                                                                id = "12"
                                                                game.Workspace.PetEquip.Remote:FireServer(id)
                                                            else
                                                                if chat == "Ruby" then
                                                                    id = "13"
                                                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                                                else
                                                                    if chat == "Gold" then
                                                                        id = "14"
                                                                        game.Workspace.PetEquip.Remote:FireServer(id)
                                                                    else
                                                                        if chat == "Diamond" then
                                                                            id = "15"
                                                                            game.Workspace.PetEquip.Remote:FireServer(id)
                                                                        else
                                                                            if chat == "Uranium" then
                                                                                id = "16"
                                                                                game.Workspace.PetEquip.Remote:FireServer(id)
                                                                            else
                                                                                if chat == "Flame Doggo" then
                                                                                    id = "17"
                                                                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                else
                                                                                    if chat == "Flame Kitty" then
                                                                                        id = "18"
                                                                                        game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                    else
                                                                                        if chat == "Flame Bunny" then
                                                                                            id = "19"
                                                                                            game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                            if chat == "Flame Beary" then
                                                                                                id = "20"
                                                                                                game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                            else
                                                                                                if chat == "Flame Birdy" then
                                                                                                    id = "21"
                                                                                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                                else
                                                                                                    if chat == "Fire Orb" then
                                                                                                        id = "22"
                                                                                                        game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                                    else
                                                                                                        if chat == "Living Flames" then
                                                                                                            id = "23"
                                                                                                            game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                                        else
                                                                                                            if chat == "Inferno Torch" then
                                                                                                                id = "24"
                                                                                                                game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                                            else
                                                                                                                if chat == "Fire Demon" then
                                                                                                                    print("Detect")
                                                                                                                    id = "25"
                                                                                                                    game.Workspace.PetEquip.Remote:FireServer(id)
                                                                                                                end
                                                                                                            end
                                                                                                        end
                                                                                                    end
                                                                                                end
                                                                                            end
                                                                                        end
                                                                                    end
                                                                                end
                                                                            end
                                                                        end
                                                                    end
                                                                end
                                                            end
                                                        end
                                                    end
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end)
    end
end)

2 answers

Log in to vote
0
Answered by 4 years ago

Hello CandyWreckEpicness!

Looking over your code, I would strongly recommend you change how this works; it is very cluttered and doesn't seem intuitive.

I would recommend you separate parts of the message and use one of the message parts to index an array containing information stored about the pets and or whatever you need to store.

Example:

local Players = game:GetPlayers()

local player = Players.LocalPlayer
local command = "/petequip"

local petInfo = {
    doggo = {
        id = 1
        -- Any other data...
    },
}

player.Chatted:Connect(function(msg)
    msg = msg:split(" ") -- This will split the message every space
    if (msg[1]:lower() == command) then
        local pet = petInfo[msg[2]:lower()
        if (not pet) then 
            return
        end
        -- FireServer:(pet.id)
    end
end

This is a very rough model of what I was trying to explain; let me know if this helps at all!

Ad
Log in to vote
0
Answered by 4 years ago

I figured out an easy way myself.

player.Chatted:Connect(function(chat)
    if chat == "/petequip" then
        peton = true
        game.StarterGui:SetCore("ChatMakeSystemMessage",{
            Text = "Now say the pet you want to equip. Make sure to captialize the first letter!";
            Color = Color3.new(1, 1, 1);
            Font = Enum.Font.Arcade;
        })
        player.Chatted:Connect(function(chat)
            if peton == true then
                peton = false
                local id = "0"
                if chat == "Doggo" then
                    id = "1"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Kitty" then
                    id = "2"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Bunny" then
                    id = "3"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Beary" then
                    id = "4"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Birdy" then
                    id = "5"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Neon Orb" then
                    id = "6"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Neon Chaos Elemental" then
                    id = "7"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Stone" then
                    id = "8"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Coal" then
                    id = "9"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Iron" then
                    id = "10"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Amethyst" then
                    id = "11"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Sapphire" then
                    id = "12"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Ruby" then
                    id = "13"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Gold" then
                    id = "14"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Diamond" then
                    id = "15"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Uranium" then
                    id = "16"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Flame Doggo" then
                    id = "17"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Flame Kitty" then
                    id = "18"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Flame Bunny" then
                    id = "19"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Flame Beary" then
                    id = "20"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Flame Birdy" then
                    id = "21"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Fire Orb" then
                    id = "22"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Living Flames" then
                    id = "23"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Inferno Torch" then
                    id = "24"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
                if chat == "Fire Demon" then
                    id = "25"
                    game.Workspace.PetEquip.Remote:FireServer(id)
                end
            end
        end)
    end
end)

Answer this question