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

Can I have some help with this map choosing?

Asked by 9 years ago

Ok, so I have a script in Workspace that jhas this text:

    h=Instance.new("Hint")
    h.Parent=game.Workspace
while wait(1) do
    h=Instance.new("Hint")
    h.Parent=game.Workspace

    script.StarterMusic:Play()
--variables 
    h.Text=""
    --round starts
    if game.Players.NumPlayers<=0 then
        while game.Players.NumPlayers<=0 do
            wait(1)
    h.Text="Waiting for 2 players..."

        end

    else
            i=5

            while wait(1) and i>0 do
        h.Text=i.." seconds until the round starts!"
        i=i-1
            end
            h.Text="Choosing a random map..."
local maps = game.ServerStorage["Maps"]:GetChildren()

            wait(3)
         map = maps[math.random(1, #maps)]
        h.Text=map
        wait(1)
    end
end

What happens is the script freezes after it chooses the map. The only error I ever get is 06:09:49.080 - String expected. I think it's the way I' choosing the map. If so, how do I fix it? If not, what is it? Please help. Thanx.

-ds

2 answers

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your Problem

You're setting the Text property to a userdata on line 30, but the Text Property takes in strings!


How To Fix

Just index the Name Property of 'map' on line 30. This way, you will be providing a string of the map's name.


Code

--No need to create a hint up here, as you do inside the while loop
while wait(1) do
    local h = Instance.new("Hint",workspace)
    script.StarterMusic:Play()
    --Check if it's less than 2, since you want there to be 2 players.
    if game.Players.NumPlayers < 2 then
        wait(1)
        h.Text = "Waiting for 2 players..."
    else
        --Just use a for loop!(:
        for i = 5,1,-1 do
            wait(1)
            h.Text = i.." seconds until the round starts!"
        end
        h.Text = "Choosing a random map..."
        local maps = game.ServerStorage["Maps"]:GetChildren()
        --Choose the map before you wait.. just more efficient.
        local map = maps[math.random(1, #maps)]
        wait(3)
        h.Text = map.Name
    end
end
Ad
Log in to vote
3
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

It says string expected, because of line 30. You made the mistake of trying to display a message, of the physical model! Instead, put h.Text = map.Name , which is the string that it's asking for!

0
Wow, I get downed twice, even though I'm correct. Shawnyg 4330 — 9y
0
Wasn't me:P Goulstem 8144 — 9y
0
Scammer? woodengop 1134 — 9y
0
Thanx! ChemicalHex 979 — 9y
0
Thanks community for bringing my points back to the original state! @dsboy55 You should Accept Goul's answer, since he elaborated more. Shawnyg 4330 — 9y

Answer this question