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

My game works through Roblox Studio but doesn't work on actual game. How do I fix this?

By the way, I almost don't know anything about coding because I am a beginner and just watch tutorials :D

Ok so, the code I have in ServerScriptService is a normal script

local dialogue = game.ReplicatedStorage.Dialogue
local type = Enum.ThumbnailType.HeadShot
local size = Enum.ThumbnailSize.Size180x180

function Message (player, speech, id)
	dialogue:FireAllClients(player, speech, id)
end
wait()
local players = game.Players:GetChildren()
local player = players[math.random(1, #players)]
local id = game.Players:GetUserThumbnailAsync(player.UserId, type, size)
wait(1)
Message(player, "Hello and welcome to my life story!", id)
wait(3.5)
Message(player, "In this story I'll be telling you about my life :D", id)
wait(5)
Message(player, "Let's get started..", id)
wait(2)
Message(player, "To proceed, please walk on the block in-front of you", id)

game.Workspace.TeleportPart.Transparency = 0
game.StarterGui.ScreenGui.Frame.Visible = false

part = game.Workspace.TeleportPart
local debounce = false

part.Touched:Connect(function(Touched)
	print("Touched")
	wait(1)
	Message(player, "Please walk inside the house in front of you ('my' house)", id)
end)

The messaging part works on Roblox Studio but not in the actual game. And when I click F9 in the actual game and click server it says:

09:28:37 -- ServerScriptService.Script:10: bad argument #2 (interval is empty) Stack Begin Script 'ServerScriptService.Script', line 10 Stack End

Reply to answer:

As I said, I am a noob so would I put -

local dialogue = game.ReplicatedStorage.Dialogue
local type = Enum.ThumbnailType.HeadShot
local size = Enum.ThumbnailSize.Size180x180

function Message (player, speech, id)
	dialogue:FireAllClients(player, speech, id)
end
local numOfPlayers = 0
local minimumPlayers = 1
repeat
	game.Players.PlayerAdded:Wait()
	numOfPlayers = #game.Players:GetPlayers()
until numOfPlayers >= minimumPlayers
local players = game.Players:GetPlayers()
local player = players[math.random(1, #players)]
local id = game.Players:GetUserThumbnailAsync(player.UserId, type, size)
wait(1)
Message(player, "Hello and welcome to my life story!", id)
wait(3.5)
Message(player, "In this story I'll be telling you about my life :D", id)
wait(5)
Message(player, "Let's get started..", id)
wait(2)
Message(player, "To proceed, please walk on the block in-front of you", id)

game.Workspace.TeleportPart.Transparency = 0
game.StarterGui.ScreenGui.Frame.Visible = false

part = game.Workspace.TeleportPart
local debounce = false

part.Touched:Connect(function(Touched)
	print("Touched")
	wait(1)
	Message(player, "Please walk inside the house in front of you ('my' house)", id)
end)

1 answer

✓ Accepted answer

this script only runs whenever the server is started, so there are no players in the server when the script runs

local players = game.Players:GetChildren()
local player = players[math.random(1, #players)]

because there are no players in the server, #players evaluates as zero, which also means that the minimum you set (which is 1) is higher than the maximum (which is 0)

you need to wait until a player joins the server (or, if your game needs it, several players join the server) before continuing

that can be done with the Players.PlayerAdded event

local numOfPlayers = 0
local minimumPlayers = 1 -- change this if you need to wait for several players to join
repeat 
	game.Players.PlayerAdded:Wait()
	numOfPlayers = #game.Players:GetPlayers() -- a player could have left since the last time PlayerAdded fired, so instead of just assuming that we can add +1 to the number of players, we can do this instead
until numOfPlayers >= minimumPlayers

local players = game.Players:GetPlayers() -- generally it's recommended that you use GetPlayers instead of GetChildren
local player = players[math.random(1, #players)]

4 comments

0

As I have said I am a noob so I have edited my question, can you please read my reply to your answer Ziannea :D

0

yes

0

Thank you but it still doesn't work. It's not working in Roblox Studio either :\

0

Nevermind it does work, I accidentally put a piece of code you told me in the wrong spot. Thank you so much!

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