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)
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?
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)
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.
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:
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)
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)â
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)
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
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.