I have this script inside a tool that when you activate the tool it changes a BoolValue (located inide the tool) to true, it does print true but the ValueOBJ(NAMED “Swinging”) dosent Change in the client nor the server , how could I fix this?
Thanks!
local swinging = script.Parent.Swinging.Value
script.Parent.Activated:connect(function()
swinging = true
print(swinging)
end)
I got a question, exchange of using bool value? Why don’t you use a variable, so, if you want to make other scripts access the variables just do this:
_G["swinging"] = false -- _G is same as shared, every script can access it, using _G.
script.Parent.Activated:connect(function()
swinging = true
print(swinging)
end)
Another way to solve this, right now in your code you define the variable ‘swinging’ to the value of the Swinging Boolean at that point. So the swinging variable has been turned into a Boolean value which is set to it the linked objects value. Instead you want to link the swinging variable to the BooleanValue object, then set it’s value later.
So in easier terms; change the first line into; local swinging = script.Parent.Swinging
Then when you change the value of swinging to true, type; swinging.Value = true
Look, you could refute my argument in any number of ways by attacking every reason I give for it, but at the end of the day you should (almost) never set things under _G.
And this is not a case that you should make an exception for. Ask any other experienced scripter why you should not use _G over BoolValues or local variables + module scripts.