So I have a function that concatenates two values together, a parameter and a GUI's text. The problem is the script attempts to concatenate a nil value. For some reason I changed the GUI's text before calling the function and it still prints it.

I'm not sure why this happens, I don't think it's a bug though but more of the syntax?4

Here is a little snippet from the script:

--Timer() takes a number and concatenates it with a GUI's Text. 
local function Timer(formula)
	
	if formula == nil then
		TimerGui.Enabled = false
	else
		TimerGui.Enabled = true
		TimerText.Text = (TimerText.Text..formula) 
	end
end


--Tool activation event:
local function ToolMouseClick(Mouse)
	print("Tool clicked")
	if player.Team ~= game.Teams.Survivors and player.Character.Humanoid.Health ~= (0) then
		Tool:Destroy()
		return
	end
	Timer.Text = ("Flashbang detonating in:  ")
	Timer(1) 
end

Thanks for viewing this!

3 comments

1

im guessing formula is nil. when are you calling Timer? either that or your code is getting confused with the function timer and the variable timer. when it comes to scope, if you have a variable named timer and then a function named timer declared after that, it will favor the function since that was what was most recently written. 

1

https://pastebin.com/7HTrkwW1 If I had the following code, it would error since the code thinks you're referring to the function timer instead of the variable timer.

0

Thanks it worked!