####The formatting of the code is screwed, read here for information on how to format your questions/answers.
The problem here is the fact that you wrongly assume that the rocket variable is a reference to the Enabled property of the ParticleEmitter. If and whenever the Enabled property changes, your variable will not update. To solve your issue, you would have the variable hold the ParticleEmitter object itself, and make a direct access to the Enabled property.
#Reference vs Value
It is important that you know the difference between a reference and a value.
##Reference
In Lua, for example, tables are passed by reference.
local t1 = {"hello", "world", "foo", "bar"}
local t2 = {"hello", "world", "foo", "bar"}
local t1ref = t1
table.insert(t1, "test")
for _, v in ipairs({t1, t2, t1ref}) do
print(table.concat(v, ", "))
end
t1 and t1ref both have the same exact table in memory and t2 is a different table even if it has the same values in the same position. Changes made to t1 or t1ref will affect t1 and t1ref.
##Value
Data like booleans and strings are passed simply by value.
local str = "hello"
local str2 = str
str = "world"
print(str, str2)
Despite str2 being set to str, both variables have different memory and so modifying one value will not modify the other.
#Final product
local rocket = workspace.fire.ParticleEmitter
local button = script.Parent
local function click()
rocket.Enabled = script.Value.Value
end
script.Parent.MouseButton1Click:Connect(click)
######Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
5 comments
Sorry not all the code went in.
Instead of not having the enabled value be a variable, Instead just have the emitter itself be a variable and do "rocket.Enabled = false" cause sometimes Roblox lua can be a little weird when it comes to variable values and full on objects
rocked.Enabled = false
That is because OP does not know the difference between a reference and a value, I'm typing up an answer right now
Thank you! <3