Function isn't firing?

local ATime
Progress = function(Name,Intro,ATime)
	print(Name)
	print(Intro)
	print(ATime)


print("Getting the model")
local A = game.ReplicatedStorage.Abnormalities
local LOA = game.ReplicatedStorage.Abnormalities:GetChildren()
local CA = math.random(#LOA)
print(LOA[CA])

for i,RA in pairs(LOA) do
	if LOA[CA] == RA then
		print("Successful find!")
		RA.Parent = workspace
	end
end

repeat
	wait(1)
	ATime = ATime - 1
	print(ATime)
until ATime == 0
	
end
script.AData.Event:Connect(Progress)

My function isn’t firing at all, the script does nothing. there are no errors or prints. why is this the case?
(my script is in the workspace)

1 Like

Probably because the BindableEvent didn’t even fire

when i did:

script.AData.Event:Connect(Name,Intro,ATime)
	print(Name)
	print(Intro)
	print(ATime)
end)

the event did fire but i can’t use this method because i can no longer use the variables from the event. i tried moving the “end)” to the end of the script but that just has the same effect (nothing happens with no errors)

I think that using “Return” may fix my issue, but i do not know how it impliment it correctly here as i’ve rarley used it, if at all. would this help or am i just looking at my issue incorrectly?

Why don’t you just declare the function rather than as a variable? Like this:

local function Progress(Name,Intro,ATime)
	print(Name)
	print(Intro)
	print(ATime)
end)

script.AData.Event:Connect(Progress)

I don’t see what the difference would be. also I put this into my script to test if it’d work but the values inside are still concidered “Nil” making no change (it also said the “)” was an error so i removed it, same issue though)

Does your event pass those Variables?

They will be nil if they aren’t passed. If you aren’t trying to use the variables you already declared in your code, place the function after the variable declaration, and don’t include any variable names in the parenthesis.

They do,

The bindable event sends information to this script, which is recieved, because putting prints before the “end)” prints the variable contents

Issue is that i can’t use it outside the function basically, i get this error when i do

image

(Nil is meant to be the number value which is what ATime is, and that prints as “10” within the function)

Also, you shouldn’t declare a function like this:

Progress = function()

for a few reasons. Firstly, you are declaring it as a global variable, which shouldn’t be necessary and is generally a big no-no. Also, it makes your code harder to read. As well, in Lua you need to include the end keyword to declare the end of the function code. Here, you have the end placed after all of your other code. You may want this code running as part of the function, if that is the case, then going back to the code neatness, you should indent those lines so it is apparent that they are all part of the function.

Furthermore, your problem may be the variable ATime, in this snippet you sent, it is never given a value, and yet you are subtracting from it. If it’s value is nil, or even 0, then this part of your code will be an infinite loop:

repeat
	wait(1)
	ATime = ATime - 1
	print(ATime)
until ATime == 0

Okay I see what you are trying to do now. You need to declare the variables in the script, and then within the function set them to the variables passed. It should look something like this:

local Name
local Intro
local ATime
local function Progress(newName,newIntro,newATime)
	print(Name)
	print(Intro)
	print(ATime)
	Name = newName
	Intro = newIntro
	ATime = newATime

	print("Getting the model")
	local A = game.ReplicatedStorage.Abnormalities
	local LOA = game.ReplicatedStorage.Abnormalities:GetChildren()
	local CA = math.random(#LOA)
	print(LOA[CA])

	for i,RA in pairs(LOA) do
		if LOA[CA] == RA then
			print("Successful find!")
			RA.Parent = workspace
		end
	end

	repeat
		wait(1)
		ATime = ATime - 1
		print(ATime)
	until ATime == 0
end

script.AData.Event:Connect(Progress)

image

They do have a value, the first line is the name, second a description and the third one is a number (10)
ATime is set as 10 and it is printed which should mean that ATime should be 10, not nil, yet the script sets it as Nil after “end)”

I did try this earlier (setting variables before the function) but they haven’t made a change though

Please copy and send the entire script. I can’t help unless I see what the variables are set too. The first snippet you sent shows the declaration of the ATime variable without a value, but now you are saying you gave it a value. This is confusing, you should only be declaring it with local once.

The variables are being applied via a Bindable Event the script for that is here:

data = game.workspace.MiscItems.GameSorting.AData
AnoName = "[TESTING CUBE]"
AnoIntro = "This one's a first. Literally! meet the first Abnormality introduced, Say hello to the TESTING CUBE!"
AnoTime = 10

Monaetr = script.Parent
Plrs = game.Players
print(Plrs)
wait(3)


if script.Parent.Parent == workspace then
	BGS = game.ReplicatedStorage.Abnormalitymusic["Dance"]:Clone()
	BGS:Play()
	BGS.Parent = workspace
	data:Fire(AnoName, AnoIntro, AnoTime) -- varibles being sent to the current script

AnoName becomes Name, AnoIntro becomes Intro and AnoTime becomes ATime (sorry for the confusing varible settings)
(this was on a seperate script)

And for the current script i just used what you gave me

local Name
local Intro
local ATime
local function Progress(newName,newIntro,newATime)
	print(Name)
	print(Intro)
	print(ATime)
	Name = newName
	Intro = newIntro
	ATime = newATime

	print("Getting the model")
	local A = game.ReplicatedStorage.Abnormalities
	local LOA = game.ReplicatedStorage.Abnormalities:GetChildren()
	local CA = math.random(#LOA)
	print(LOA[CA])

	for i,RA in pairs(LOA) do
		if LOA[CA] == RA then
			print("Successful find!")
			RA.Parent = workspace
		end
	end
-- everything works up until this point
	repeat
		wait(1)
		ATime = ATime - 1
		print(ATime)
	until ATime == 0
end

script.AData.Event:Connect(Progress)

AData is a remoteEvent, correct? Sorry, it’s a bindableEvent, you already said that im dumb

Yeah, since both scripts are on the server, i’m using it to do Server-Server “communication” since Remote events / functions do Client-server or Server-client etc

So, the script is in ReplicatedStorage, and it’s called ‘GameSorting’, correct?

Yeah, this script is in the replicated storage area

Okay, so your issue is that scripts do not run in ReplicatedStorage. You need to move it to either ServerStorage or ServerScriptService (the latter is recommended). Make sure your first script is corrected to the new location of the script and event. With that change, it should work.

I moved it and changed the directory to the script like you said, but nothing happens now. no error anymore but nothing happens also.

Also it did run in replicated storage, just not completley