I am using Crazyman32’s AeroGameFramework, and I am creating a round based game. I am trying to call a function that is identified in the :Start() area of the round service with a string stored in a variable.
Here is the code I tried:
local event = events[math.random(1,#events)]
[event](player)
“events” is a table containing 4 strings, and each function is named after each string in the table.
I get the error ServerStorage.Aero.Services.RoundService:54: attempt to call a nil value
How do I call the function using the string stored in the variable “event”?
I removed the square brackets, however I got the same error. 14:26:39.956 - ServerStorage.Aero.Services.RoundService:63: attempt to call a string value
(Different line because I added code above that block in the script)
Well that’s your issue. You’re literally trying to call a string value. Let’s say the result of math.random(1, #events) ends up being 3 then what the event variable ends up being is "Explode".
Do you have a folder in ServerStorage or ReplicatedStorage which has all your RemoteEvents?
Yes, and then that’s my question. How do I use a string value to call a function named the same thing as the value of the string?
This is all in a ServerScript created with AeroGameFramework, and I have no events besides one that updates the status bar at the top of the screen (a text label)
Yes we get that,but when you do #events your counting everything inside the table and going by 1 to the number of things in the table and selecting 1 thing at random
It sounds like an event system for a minigame where something random happens to a player and he is trying to randomize what happens.
Here is an example that would work for randomizing events (this is a module per event basis as it would become more organized than having every event inside a table): Example.rbxl (15.3 KB)