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

Why isn't the group name displaying as the text?

Asked by
Valiux 27
8 years ago

I have a chat script in a server script in a gui in startergui. For some reason my script doesnt work but I don't know why. There are no errors.

local isAdmin = {["Valiux"] = true, [""] = true, [""] = true}

function onChatted(message, player)
    if message:sub(1, 6) == "!raid " and isAdmin[player.Name] then
        local gid = message:sub(7)
        local group = game:GetService("GroupService"):GetGroupInfoAsync(gid)
        local name = group.Name
        local total = "Raid Status: Official - "..name
        for i = 1,#total do
            script.Parent.rs.Text = string.sub(total, 1, i)
            wait(.1)
        end
    end
end


game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)
0
If it's a studio test, your name is Player1 rather than Valiux. Other than who knows. Try using breakpoints. cabbler 1942 — 8y
0
You shouldn't have server scripts in StarterGui/PlayerGui. Use ServerScriptService. OldPalHappy 1477 — 8y
0
you want a server side script to play inside of the client? Volodymyr2004 293 — 8y

1 answer

Log in to vote
0
Answered by
tkcmdr 341 Moderation Voter
8 years ago

Hey there, Valiux!

The first thing to consider is that server scripts really should not run on the client. It's bad practice, and will not work correctly (if at all) under many circumstances. The client and server should never be intertwined, though that's a subject for another day. Let's jump into the solution:

We will make two scripts. One local script to change the GUI's text, and another server script to tell the local script when to do so. For the sake of cleanliness, I'm going to make another special type of script, called a Module, to store the admins. Observe:

The module, named Admins

-- The module. Let's assume you put it in ServerStorage.

--[[ A list of players that have admin privileges. The format is as follows:

    ["USERID"] = true;  -- The username of the player, for clarity.
    ["USERID"] = true;  -- The username of the player, for clarity.
    ["USERID"] = true;  -- The username of the player, for clarity.
    ...
--]]

return
{
    -- I happen to know that your UserID is 36872500. Unlike your name, it never changes.
    ["36872500"] = true;    -- Valiux
};

The server script

-- Server script:

-- A list of admins. require() gets whatever content is returned by the module, in this case, the admins.
local Admins        = require(game.ServerStorage:WaitForChild("Admins"));

-- A remote event that will tell a specific player's client to change the GUI text.
local OnChatted = Instance.new("RemoteEvent", game.ReplicatedStorage);

local GroupService  = game:GetService("GroupService");

OnChatted.Name  = "OnChatted";

-- When an admin says "!raid GROUPID", this function will tell his client to change its text, and supplies the group name required.
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message)
        if (string.sub(message, 1, 6) == "!raid " and Admins[player.UserId]) then
            local groupID   = string.sub(message, 7);
            local group = GroupService:GetGroupInfoAsync(groupID);

            -- When we supply the player, we're just telling OnChatted which player we want to affect. Only the group name is actually sent.
            OnChatted:FireClient(player, group.Name);
        end;
    end);
end);

And finally, the client:

local OnChatted = game.ReplicatedStorage:WaitForChild("OnChatted");

-- When OnChatted is fired, change the text of rs.
OnChatted.OnClientEvent:connect(function(groupName)
    local text = "Raid Status: Official - " .. groupName;

    for i = 1, #text do
        -- I implore you to name 'rs' something more descriptive...
        script.Parent.rs.Text = string.sub(text, 1, i);

        wait(0.1);
    end;
end);

All right! I think I got everything. Give this solution a try, and let me know how it works for you. If there are any mistakes I made, do let me know. Have a nice day, Valiux, and best of luck with your game!

Warm regards, tkcmdr

Ad

Answer this question