–Purpose
I want the script to detect if the players wearing a certain suit and if they are it disables canTouch to certain parts.
–How im doing it
Im doing this by seeing the change in the string value when its equipped, when equipped its value changes to its name “Basic Top” and when its off it changes to nothing.
–Problem
Currently im testing using prints and it only prints “off” when i unequip and equip that certain suit, but it should be saying “on” when equipped, not “off”.
local plr = game.Players.LocalPlayer
local suitType = plr:WaitForChild("ArmorEquipped")
local torso = suitType.Torso
torso:GetPropertyChangedSignal("Value"):Connect(function()
if torso.Value == "Basic Top" then
print("on")
elseif torso.Value ~= "Basic Top" then
print("off")
end
end)
I hope its just a common error. Also hope i havent been vague
I did check before and there was a space even tho there doesnt look like to be one, let me check again.
Also cant check rn theres a issue on studio so cant use
FWIW: ValueBase (the abstract superclass for all xValue instances) has a special version of the Changed event that fires with the new value so you don’t need to use GetPropertyChangedSignal for any ValueBases.
ValueBase.Changed:Connect(function (newValue)
print("Changed value to:", newValue)
end)
Furthermore, the value of a ValueObject is a reference to an instance, so this check is not valid because an instance is not equal to a string. You would need to access the name property first but do your dilligence in making sure it’s not a nil value.
torso.Changed:Connect(function (newValue)
if typeof(newValue) ~= "Instance" then
-- Value is nil
elseif newValue.Name == "BasicTop" then
-- BasicTop is equipped
end
end)