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

i need some help with adding a value from a script into my intermission script?

Asked by 6 years ago
Edited 6 years ago

i'm making a sort of castle defend game where i have to use a intermission/round script. but everytime i try to test it. it won't work. please help!

print("Intermission/Rounds are online")
print("If all goes well. These will all run. Right?")
print(":)")

local playercount = script.plrs.Value
local roundtime = 120
local winners = "?"
function onPlayerAdded(player)
     playercount.Value = playercount.Value + 1
end

   if playercount.Value >= 1 then
    script.Parent.Text = "Intermission - 3"
    wait(1)
    script.Parent.Text = "Intermission - 2"
    wait(1)
    script.Parent.Text = "Intermission - 1"
    wait(1.5)
    script.Parent.Text = "Round starting..."
    wait(3)
    script.Parent.Text = "Round time left: roundtime"
    wait(roundtime)
    script.Parent.Text = "GAME OVER!"
    wait(1.5)
    script.Parent.Text = "winners win!"
 end
0
is this the full script? User#5423 17 — 6y
0
yes. slay_unknown -3 — 6y
0
Read my bio. hiimgoodpack 2009 — 6y
0
hahahahaha rilgundam 65 — 6y
View all comments (4 more)
0
not really helping. :I slay_unknown -3 — 6y
0
The onPlayerAdded function won't work because it's not connected, should be game.Players.PlayerAdded:connect(function() end) DjinoKip 78 — 6y
0
There is a very well put together tutorial on Youtube from Alvinbloxx, its a five part series, it goes over round scripts, I highly recommend it - https://www.youtube.com/watch?v=xgeUbOFQ8sc Never2Humble 90 — 6y
0
READ MY DAMN BIO AND INDENT PROPERLY hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by
R_alatch 394 Moderation Voter
6 years ago
Edited 6 years ago

The problem is, you aren't connecting your PlayerAdded function. Whenever you make a function, unless you call it, it won't do anything. In order to call it, you would use this.

game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)

What the above does is it gets the service "Players" from the game and fires whenever a player is added there. It will then fire the "onPlayerAdded" function that you are trying to fire.

Something else I wanna teach you are for loops. The part in your script where you make an individual line for each number you're counting down, you shouldn't be doing that. What you can do it make a "for" loop that will be a variable that starts at 3, ends at 0, and counts down -1 every second. This is what it looks like.

for countdown = 3, 0, -1 do --creates the for loop
    script.Parent.Text = "Intermission - " .. countdown --this is the same as what you had, except since the countdown variable was made in this for loop, you wanna concatenate the variable
    wait(1) --adds a wait one so it doesn't instantly loop through the entire thing
end

Hopefully this helps and if you wanna learn more about these 2 things I will leave a wiki below!

Your entire script with what was showed above:

local playercount = script.plrs.Value
local roundtime = 120
local winners = "?"

function onPlayerAdded(player)
    playercount.Value = playercount.Value + 1
end

game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)

if playercount.Value >= 1 then
    for countdown = 3, 0, -1 do
        script.Parent.Text = "Intermission - " .. countdown
        wait(1)
    end

    wait(1.5)

    script.Parent.Text = "Round starting..."
    wait(3)

    script.Parent.Text = "Round time left: " .. roundtime --also right here, you didn't do like showed in my for loop example above how it's supposed to concatenate the roundtime variable
    wait(roundtime)

    script.Parent.Text = "GAME OVER!"
    wait(1.5)

    script.Parent.Text = "Winners win!"
end

PlayerAdded For Loops

Ad

Answer this question