Help with Script!

Please help me, idk what i did wrong with this script…

	wait() 
	if script.Parent.Parent.Value.Value == 10 then
		script.Parent.SwordScript.Disabled = true
	elseif script.Parent.Parent.Value.Value == 5 then
		script.Parent.SwordScript.Disabled = false
	end
end

–btw the script is in “Enable/Disable”…

the script is supposed to detect if the value = 10
when it detects it as 10 it enables the “SwordScript” script
and if the value is 5 then it disables…

snippet

Well, what is it you want the script to do? Right now I can’t really tell you what needs to be fixed because I can’t be sure what you want it to do, I can only see what it currently does.

You’re going too high in the parent list,
Parent.Parent.Value → .Parent.Value

3 Likes

By using .Parent.Parent you are going to the parent of ClassicSword

the script is supposed to detect if the value = 10
when it detects it as 10 it enables the “SwordScript” script
and if the value is 5 then it disables…

Is this in a while loop? I see an extra end and a wait() leading me to assume it is. If it is in a while loop, it would likely be better to do this instead.

script.Parent.Value:GetPropertyChangedSignal("Value"):Connect(function()
  if script.Parent.Value.Value == 10 then
		script.Parent.SwordScript.Disabled = true
	elseif script.Parent.Value.Value == 5 then
		script.Parent.SwordScript.Disabled = false
	end
end)

The reason being that the code will now only run when that value changes, rather than checking over and over again after waiting in between checks.

Please read my reply, it might be your fix.

hmm maybe im using the wrong value… i have a string value in set do you think that might be the reason it dont work?? otherwise, its still not working

hmm maybe im using the wrong value… i have a string value in set do you think that might be the reason it dont work??? otherwise, its still not working

If it’s a string value, you are comparing it to a number it’s a different value. Numbers and strings are stored differently inside the computer, so to check them you need to make sure they are the same type. The easiest way to do this would be to put the numbers in your script in quotes to make them strings instead of numbers.

if script.Parent.Parent.Value.Value == "10" then --Now the 10 is a string, not a number and can now be compared correctly to the value
		script.Parent.SwordScript.Disabled = true
	elseif script.Parent.Parent.Value.Value == "5" then
		script.Parent.SwordScript.Disabled = false
	end

Either that or to make the value an IntValue or NumberValue instead if the value doesn’t need to be a string

hmm, I’m trying it right now but idk if its possible to disable the script like this. im trying everything and it just wont disable the script. u got any other way on how to make a value that can disable a script?

hold on that thought actually… i think i know how to fix it

hey wait, sorry to ask again but do u know how to make it so the script keeps checking for the value?

-btw thx for all ur help

script.Parent.Value.Changed:Connect(function()

end)
script.Parent.Value:GetPropertyChangedSignal("Value"):Connect(function()
  if script.Parent.Value.Value == 10 then
		script.Parent.SwordScript.Disabled = true
	elseif script.Parent.Value.Value == 5 then
		script.Parent.SwordScript.Disabled = false
	end
end)

The code I sent earlier should do that. Just note that it has to be an Int or Number value there for how it currently is set up, otherwise it will fail both of the conditionals

He asked how to check when it changed. Not execute a code when it is changed.

While technically true, in context it seems that what he wants to do is run this code. I already supplied a similar answer earlier with more information about it, though I probably should have quoted that instead of copying it.

SOLVED!!! I want to thank @tlr22 @lrisDev @tlr22 @DevCramp for using their time on solving this issue!!!
(btw sry for ping if y’all get mad :grinning:)

1 Like