I got this code here, and It’s broken. It’s also hard to understand (for me at least), I’m not sure what I was thinking writing this, if anyone can help me fix it will be appreciated.
(eventtype.value and current.value are not being updated when the functions are ran)
(the while wait(2) do part is just a placeholder)
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local events = 5
chosenEvent = ""
local ce = chosenEvent
local values = rep.Values
local current = values.CurrentEvent
local eventtype = current.EventType
local highlight = current.ObjectToHighlight
local function chooseEvent()
chosenEvent = math.random(1, events)
end
local function executeEvent()
if ce == 1 then
eventtype.Value = "Player"
current.Value = "A player will get +10 jump power"
elseif ce == 2 then
eventtype.Value = "Player"
current.Value = "A player will become sparkly"
elseif ce == 3 then
eventtype.Value = "Arena"
current.Value = "Arena: Fire will fall from the sky"
elseif ce == 4 then
eventtype.Value = "Plate"
current.Value = "Someone's plate will light on fire"
elseif ce == 5 then
eventtype.Value = "Plate"
current.Value = "Someone's plate will flip upside-down"
end
end
while wait(2) do
chooseEvent()
executeEvent()
print(ce, eventtype.Value, current.Value)
end
What is this even for? What are you trying to fix? Also what is the issue / what happens when you try to run it? Please be more specific or we can’t help you
I believe it’s because you are using the same name, current, for both a local variable and a property of the values object. You need to either use different names for different variables, or use the full path to access the property.
For example, you have this line:
local current = values.CurrentEvent
This means that current is a local variable that refers to the CurrentEvent property of the values object. However, later in your code, you have this line:
current.Value = “A player will get +10 jump power”
This means that you are trying to set the Value property of the local variable current, not the CurrentEvent property of the values object. This will not work, because the local variable current does not have a Value property. You need to either change the name of the local variable, or use the full path to access the property, like this:
values.CurrentEvent.Value = “A player will get +10 jump power”
The same applies to the eventtype variable and property. You need to make sure that you are using the correct names and paths for your variables and properties, otherwise they will not be updated correctly.
That’s the structure of the values object in the workspace, which contains the CurrentEvent property. However, in your code, you are using a local variable named current to refer to the CurrentEvent property. This is not the same as the property itself. You need to use the full path to access the property, like this:
values.CurrentEvent.Value = “A player will get +10 jump power”
Otherwise, you are just setting the value of a local variable that has nothing to do with the property.