Function not Working

So my problem is basically that when I try to run the stop function I get the error “unknown global”
Can someone help me with this?

local round = game.ReplicatedStorage.round
local games = game.ServerStorage.minigames:GetChildren()
local minitime = game.ReplicatedStorage.minitime
local mininame = game.ReplicatedStorage.mininame
local stat = game.ReplicatedStorage.gamestatus
local death = game.ServerScriptService.dead

death.Enabled = false


local function start()
	local mgame = games[math.random(#games)]
	local gameclone = mgame:Clone()
	gameclone.Parent = workspace
	print(mgame)

	minitime.Value = gameclone.Time.Value
	mininame.Value = gameclone.Name

	
	task.wait(.5)
	for _, plr in pairs(game.Players:GetChildren()) do
		plr.Character.Humanoid.Sit = false
		plr.Team = game.Teams.Playing
		death.Enabled = true
		wait(.01)
		plr:LoadCharacter()
	end

	round.Value = true
	
	local function stop()
		gameclone:Destroy()
		for _, plr in pairs(game.Players:GetChildren()) do
			plr:LoadCharacter()
		end
		round.Value = false
		death.Enabled = false
	end
end


while true do 
	for i = 15, 0, -1 do 
		stat.Value = "Intermission: " .. i
		wait(1)
	end
	start()
	for i = minitime.Value, 0, -1 do 
		script.Parent.towel.Text = mininame.Value .. ": " .. i
		wait(1)
	end
	stop()
end

What’s the full error? “Unknown global …”

Your stop function is inside the start function so it’s limited to that scope meaning that you can’t call it outside, but you did call it (before last line) which is what’s causing the error.

1 Like

also please just make vars for the services

local Rep = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local SSS = game:GetService("ServerScriptService")

local round = Rep.round
local minitime = Rep.minitime
local mininame = Rep.mininame
local stat = Rep.gamestatus
local games = SS:WaitForChild("minigames"):GetChildren()
local death = SSS.dead

For readability and understandability, write more descriptive names.

since there’s only 3 i don’t see how it’s hard to understand what rep, ss, and sss means
he could change the names to something that’s easier to understand

Your “gameclone” variable is in “start” function and in “stop” function.

3 is larger than 0.
Having names like “sss” makes the code confusing, if someone’s new to Roblox Studio and reads codes like this, there is absolutely no way he will understand what each of them mean, but if you write something like “serverScriptService”, they code easily guess what that variable is.


That was just a recommendation for better code nothing else.

“ServerScriptService” is still long so there would be no point in shortening that part of the code (imo) that’s why i would go for a shorter name
and again i still don’t see how it’s hard to figure out that SSS means ServerScriptService when it’s on the same line

I think you wrote this wrong as you just said what you did is pointless…?

^^


If you would like to continue this conversation please pm to avoid flooding the post.
1 Like

you don’t understand
it’s fine

You wouldnt have a Variable with A Huge name, it makes your code look weird, like for Example:

local ExampleOfALongVariableThatCanBeShortened = 10
-- for readability sake, please shorten your variables
-- so you dont haave to look at an entire sentence
-- to understand your code.
-- if you need help determining which is which
-- use a comment, not that hard.
-- you dont need to use it if you can tell
-- the Path the Variable is assigned to.


local SSS = game.ServerScriptService -- Easy to Determine what it is by looking at what it is assigned

(I meant to direct this to @msix29)

1 Like

ServerScriptService isn’t a huge name and please read my replies correctly before replying.


Please stop replying here and pm me instead.

Well, when I try to move the stop function outside of the start function I can’t access the gameclone variable, so how would I be able to reference it in another function?

at the start of your code write:

local gameClone = -- set some default value

and inside your start(), type:

gameClone = value
-- ^ without local

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.