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

I need a script that doesn't run twice when another player joins the game. How do I fix this?

Asked by
vra000 22
3 years ago

I have a working minigame with a working timer that starts from: "A minigame will be chosen in 15 seconds", but, when a new player joins the game, the gui for THAT player starts over from 15 seconds.

Here is my code:

local part = workspace.start
local nice = workspace.grass

while true do
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 15 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 14 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 13 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 12 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 11 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 10 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 9 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 8 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 7 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 6 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 5 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 4 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 3 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 2 seconds"
    wait(1)
    script.Parent.Text = "A minigame will be chosen in 1 second"
    wait(1)
    script.Parent.ImageLabel.Visible = true
    wait(1)
    script.Parent.Text = "The round will begin in 14 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 13 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 12 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 11 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 10 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 9 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 8 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 7 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 6 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 5 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 4 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 3 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 2 seconds"
    wait(1)
    script.Parent.Text = "The round will begin in 1 second"
    wait(1)
    script.Parent.Text = "The round is beginning!"
    wait(1)
    for _,player in pairs(game:GetService("Players"):GetPlayers())do
        if player and player.Character then
            player.Character:MoveTo(part.Position)
        end
    end
    wait(0.1)
    script.Parent.ImageLabel.Visible = false
    wait(1)
    script.Parent.Text = "00:30"
    wait(1)
    script.Parent.Text = "00:29"
    wait(1)
    script.Parent.Text = "00:28"
    wait(1)
    script.Parent.Text = "00:27"
    wait(1)
    script.Parent.Text = "00:26"
    wait(1)
    script.Parent.Text = "00:25"
    wait(1)
    script.Parent.Text = "00:24"
    wait(1)
    script.Parent.Text = "00:23"
    wait(1)
    script.Parent.Text = "00:22"
    wait(1)
    script.Parent.Text = "00:21"
    wait(1)
    script.Parent.Text = "00:20"
    wait(1)
    script.Parent.Text = "00:19"
    wait(1)
    script.Parent.Text = "00:18"
    wait(1)
    script.Parent.Text = "00:17"
    wait(1)
    script.Parent.Text = "00:16"
    wait(1)
    script.Parent.Text = "00:15"
    wait(1)
    script.Parent.Text = "00:14"
    wait(1)
    script.Parent.Text = "00:13"
    wait(1)
    script.Parent.Text = "00:12"
    wait(1)
    script.Parent.Text = "00:11"
    wait(1)
    script.Parent.Text = "00:10"
    wait(1)
    script.Parent.Text = "00:09"
    wait(1)
    script.Parent.Text = "00:08"
    wait(1)
    script.Parent.Text = "00:07"
    wait(1)
    script.Parent.Text = "00:06"
    wait(1)
    script.Parent.Text = "00:05"
    wait(1)
    script.Parent.Text = "00:04"
    wait(1)
    script.Parent.Text = "00:03"
    wait(1)
    script.Parent.Text = "00:02"
    wait(1)
    script.Parent.Text = "00:01"
    wait(1)
    script.Parent.Text = "00:00"
    wait(1)
    for _,player in pairs(game:GetService("Players"):GetPlayers())do
        if player and player.Character then
            player.Character.Humanoid.Health = 0
        end
    end
   wait(1)  
   script.Parent.Text = "A minigame will be chosen in 15 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 14 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 13 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 12 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 11 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 10 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 9 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 8 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 7 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 6 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 5 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 4 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 3 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 2 seconds"
wait(1)
script.Parent.Text = "A minigame will be chosen in 1 second"
wait(1)
script.Parent.OtherImageLabel.Visible = true
wait(1)
script.Parent.Text = "The round will begin in 14 seconds"
wait(1)
script.Parent.Text = "The round will begin in 13 seconds"
wait(1)
script.Parent.Text = "The round will begin in 12 seconds"
wait(1)
script.Parent.Text = "The round will begin in 11 seconds"
wait(1)
script.Parent.Text = "The round will begin in 10 seconds"
wait(1)
script.Parent.Text = "The round will begin in 9 seconds"
wait(1)
script.Parent.Text = "The round will begin in 8 seconds"
wait(1)
script.Parent.Text = "The round will begin in 7 seconds"
wait(1)
script.Parent.Text = "The round will begin in 6 seconds"
wait(1)
script.Parent.Text = "The round will begin in 5 seconds"
wait(1)
script.Parent.Text = "The round will begin in 4 seconds"
wait(1)
script.Parent.Text = "The round will begin in 3 seconds"
wait(1)
script.Parent.Text = "The round will begin in 2 seconds"
wait(1)
script.Parent.Text = "The round will begin in 1 second"
wait(1)
script.Parent.Text = "The round is beginning!"
    wait(1)
    game.ReplicatedStorage.ClassicSword:Clone().Parent = game.StarterPack
    wait(1)
    for _,player in pairs(game:GetService("Players"):GetPlayers())do
        if player and player.Character then
            player.Character.Humanoid.Health = 0
        end
    end
    wait(5)
for _,player in pairs(game:GetService("Players"):GetPlayers())do
    if player and player.Character then
        player.Character:MoveTo(nice.Position)
    end
    end
    wait(2000)
    end

I have tried setting ResetOnSpawn on False, but it still didn't work. I am making this game for Christmas, so my friends can compete to see who can get the robux gift card from me. Please Help! (part is the start of the first minigame, and nice is the start of the second minigame.)

0
Instead of making your code so long and doing separate wait statements to make timers function, why don't you use for loops? https://education.roblox.com/en-us/resources/repeating-tasks-with-for-loops kingblaze_1000 359 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Here's some very helpful tips to help you with the countdown. First of all, I suggest using an IntValue (Int means Integer, which means whole numbers like 1, 2, 290, etc.) and put in ReplicatedStorage. And you can use a server script for the countdown part.

Server Script (This is where most of your code should be in)

local countdown = game.ReplicatedStorage.Countdown --Reference this variable wherever your intvalue is.

for i = 30, 1, -1 do -- 1st is the start, 2nd is the end, 3rd is the increment (decreases by 1)
    countdown.Value = i --The same way you use a variable.
    wait(1)
end

Local Script (Parent should be your ScreenGui or TextLabel)

local textLabel = script.Parent.TextLabel --I always put the localscript's parent as ScreenGui.
local countdown = game.ReplicatedStorage.Countdown
countdown:GetPropertyChangedSignal("Value"):Connect(function() --This is a better alternative then countdown.Changed. Which does the same thing, except it looks for any property changed.
    textLabel.Text = "Round will begin in "..countdown.Value.." seconds!"
end

Optimisation is important. And while this doesn't solve your entire issue, you can repeat this to solve all your problems.

Ad

Answer this question