Hi. I have a piece of code that should work to my knowledge however it doesn’t. A quick rundown of the code: Tries to set a script’s Disabled property to false when the tool is parented to the Workspace.
Code:
local Tool = script.Parent
if Tool.Parent == "Workspace" then
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = false
else
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = true
end
Edit: Forgot to mention, the code doesn’t work at all. It doesn’t do freaky stuff like setting the script to true while the parent is something else from Workspace, just doesn’t work.
local Tool = script.Parent
if Tool.Parent == game.Workspace then
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = false
else
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = true
end
Parent is an instance pointer property, not a string.
So you compare the tool’s parent (which is presumed to be the workspace service, which is an instance) to of type string. Obviously, those two types will not be the same.
Instance pointer meaning it’s a reference to some instance type, not an actual object that’s stored as the parent, if that makes any sense at all.
Hopefully this clears the air a bit. @Escape_Everything gave you the functional expression.
Update: I was on the phone when I accepted the solution however didn’t test out @Escape_Everything 's solution. Sadly, it didn’t work however for any other people experiencing an issue of this sorts, here is my code!
local Tool = script.Parent
Tool:GetPropertyChangedSignal("Parent"):Connect(function()
if Tool.Parent == workspace then
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = false
else
Tool.Handle.ImpactSoundsForSingleObjects.Disabled = true
end
end)