Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I have some help with this map choosing?

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

✓ Accepted answer

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

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!

5 comments

0

Wow, I get downed twice, even though I'm correct.

0

Wasn't me:P

0

Scammer?

0

Thanx!

0

Thanks community for bringing my points back to the original state! @dsboy55 You should Accept Goul's answer, since he elaborated more.

This discussion is preserved as it was. New answers, comments, and votes are closed.