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

what is wrong with this server message script? it doesnt work at all

Asked by
zValerian 108
5 years ago

what is wrong with it. I put it in starterpack so it runs automatically. nothing happens.

game.Players.PlayerAdded:connect(function(player)
wait()
while true do
if game.Workspace.PlayerCount.Players.Value <= 2
    then
    game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = "Waiting for at least FIVE players to join..",
    Color = Color3.new(100, 100, 0),
    Font = Enum.Font.SourceSansLight,
    FontSize = Enum.FontSize.Size18,
print("made it here lol")
    })
    wait(10)
end

wait()
if game.Workspace.PlayerCount.Players.Value >= 2
    and game.Workspace.game.CanCollide == true
    then
    game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = "Welcome to the annual HUNGER GAMES",
    Color = Color3.new(100, 0, 0),
    Font = Enum.Font.SourceSansLight,
    FontSize = Enum.FontSize.Size18,
        })
    local a = true
    if a == true then
player.TeamColor = BrickColor.new("Forest green")
    wait(10)
    game.Workspace.game.CanCollide = false
    game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = "If you don't know how to play, read the description!",
    Color = Color3.new(0, 100, 0),
    Font = Enum.Font.SourceSansLight,
    FontSize = Enum.FontSize.Size18,
            })
    a = false
    local b = true
wait(10)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = "Selecting random arena...",
    Color = Color3.new(100, 100, 530),
    Font = Enum.Font.SourceSansLight,
    FontSize = Enum.FontSize.Size18,
        })
elseif 1 b == true then
wait(5)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = "Arena selected. Prepare to enter the game. May the odds be ever in your favor.",
    Color = Color3.new(322, 100, 0),
    Font = Enum.Font.SourceSansLight,
    FontSize = Enum.FontSize.Size18,
        })
b = false
local c = true
    elseif 
         c == true
        then
wait(20)
local Pos = player.Character:GetPrimaryPartCFrame()
                    player:LoadCharacter()
                    player.Character:SetPrimaryPartCFrame(Pos)
                    if player.Character:FindFirstChild("ForceField") then
                        player.Character["ForceField"]:Destroy()
                        wait(1)
                        game.ReplicatedStorage.Remotes.tp:FireServer()
                        c = false
    end                 end
end
end
end)



0
Didn't you post this question yesterday? TheeDeathCaster 2368 — 5y
0
i changed it zValerian 108 — 5y
0
Unfortunately, I don't exactly know how to help you. I'm posting this comment because you've been asking a lot of questions about your game, and I'm assuming you're making a Hunger Games replica. Looks interesting. I'm actually kind of curious as to how it is going to turn out lol. Will probably check it out when it's done. Good luck figuring things out, man! lunatic5 409 — 5y
0
thank you! zValerian 108 — 5y
View all comments (2 more)
0
Reply to your comment. This is why your script never works in StarterPlayer. Either move the script to `Workspace`/`ServerScriptService` or change it to `Local Script`. Zafirua 1348 — 5y
0
Do accept the answer so we can both earn some reputation points and close it for future references. Zafirua 1348 — 5y

1 answer

Log in to vote
0
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago

There are multiple problems on your code.

First of all, you should always indent your code properly to make it more readable.

Server Scripts do not work in StarterPlayer. They only work in either Workspace, or ServerScriptService. Consider either moving it to those locations or changing the script into Local Script.

You shouldn't be using while true do loop for this. You should make a Server Script. that invokes the Local Script. And the Local Script handles the major framework and/or communicates with Server Script if necessary.

For example

Server Sided Script

-- [Declaration Section]
--\\ Services  
local ReplicatedStorage       = game:GetService("ReplicatedStorage");
local Players                 = game:GetService("Players");

--\\ Remote Event
local OnPlayerEvent           = ReplicatedStorage:WaitForChild("OnPlayerEvent");
local RequirementEvent        = ReplicatedStorage:WaitForChild("RequirementEvent");

--\\ IntValue Adding 
local AmountOfPlayers         = script.AmountOfPlayers;

--\\ Starting Numbers of Players 
local MIN                     = 5;

-- [Processing Section]
local function On_Player_Added ()
    AmountOfPlayers.Value     = AmountOfPlayers.Value + 1;
    print(AmountOfPlayers.Value);

    if AmountOfPlayers.Value >= MIN then 
        print(AmountOfPlayers.Value .. ": Invoking!");
        RequirementEvent:FireAllClients(true);
    else 
        print(AmountOfPlayers.Value .. ": Not Enough!");
        RequirementEvent:FireAllClients(false);
    end;
end;

local function On_Player_Leaved ()
    AmountOfPlayers.Value     = AmountOfPlayers.Value - 1;
    print(AmountOfPlayers.Value);
end;

-- [Connecting Section]
Players.ChildAdded:Connect(On_Player_Added);
Players.ChildRemoved:Connect(On_Player_Leaved);

Client Sided Script

-- [Declaration Section]
--\\ Game Services 
local ReplicatedStorage       = game:GetService("ReplicatedStorage");
local Player                  = game:GetService("Players").LocalPlayer;
local Character               = Player.Character or Player.CharacterAdded:Wait();

--\\ Remote Event Location 
local RequirementEvent        = ReplicatedStorage:WaitForChild("RequirementEvent");

-- [Processing Section]
local function On_Player_Added (Value)
    if Value == true then 
        print("Enough Players: Starting Game");

--      Do Stuff 
    else 
        print("Not Enough Players");
    end
end;

-- [Connecting Section]
RequirementEvent.OnClientEvent:Connect(On_Player_Added);

Of course, there are numerous ways to do this, and this is just one of the ways. With the above code, you have to make sure that the Remote Event does not fire in the middle of the game. This can simply be achieved by using Boolean values.

Hope this gives you a starting idea on how to manage scripts. You should also always be utilizing Module Scripts.

0
It is a servermessage script not a local scrit zValerian 108 — 5y
Ad

Answer this question