Hello. I am currently trying to figure out why the script below does not work. I am trying to disable and re-enable a script by pressing a button. I does enable the script (It starts out disabled) but when I click the button, it does not enable it again. It’s a local script, and I know it has the ability to disable/enable another local script. Could someone please inform me on what I am doing wrong? Thank you for your time
Edit: forgot to mention something
local SpacesCountScript = script.Parent.Parent.Parent.FindFirstChild("IncludeSpaces")
local Button1 = script.Parent
Button1.MouseButton1Click:Connect(function()
SpacesCountScript.Enabled = not SpacesCountScript.Enabled
end)
local TextBox = script.Parent.Type
local TextLabel = script.Parent.Visualiser
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
local Text = TextBox.Text
local Letters = string.len(Text)
TextLabel.Text = Letters .. " character(s) long"
end)
Based on the code you posted, there are a couple of issues with it. Firstly, in the second script, there is an end statement at the end of the second line inside the function, which is causing the function to prematurely terminate. To fix this, you should move the end statement to the end of the function, after the line that sets the text of the TextLabel .
Secondly, the line TextBox:GetPropertyChangedSignal("Text"):Connect(function() is connecting a signal to the TextBox property changed event, but it does not seem to be updating the text of the TextLabel . To update the text of the TextLabel based on the text in the TextBox , you should add the code that sets the text of the TextLabel inside the function that is connected to the TextBox property changed event.
Here is the corrected code:
local SpacesCountScript = script.Parent.Parent.Parent:FindFirstChild("IncludeSpaces")
local Button1 = script.Parent
Button1.MouseButton1Click:Connect(function()
SpacesCountScript.Enabled = not SpacesCountScript.Enabled
end)
local TextBox = script.Parent.Type
local TextLabel = script.Parent.Visualiser
TextBox.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
local Text = TextBox.Text
local Letters = string.len(Text)
TextLabel.Text = Letters .. " character(s) long"
end)
If you are trying to toggle the Enabled property of a script, but it is not being updated. One possible way to do it is to check if the Enabled property is set to true or false , and toggle it accordingly, like this:
local SpacesCountScript = script.Parent.Parent.Parent:FindFirstChild("IncludeSpaces")
local Button1 = script.Parent
Button1.MouseButton1Click:Connect(function()
if SpacesCountScript.Enabled then
SpacesCountScript.Enabled = false
else
SpacesCountScript.Enabled = true
end
end)
This way, the Enabled property is set to the opposite of its current value each time the button is clicked.
alright, I dont even know what to do next. This script does not even enable it. I get no errors, I also checked for pathing problems, nothing. I dont even understand why it is not working. I guess ill keep looking for answers