Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I put GetPropertyChangedSignal in an if statement?

In my server script I have something that would detect for jump when jump is changed, but it's in a tool so how would I say to delete the part inside the player only when the tool is in the player.

local hum = script.Parent.Parent:FindFirstChild("Humanoid")
-- if script.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
hum:GetPropertyChangedSignal("Jump"):Connect(function()
	if hum.Jump == true then
		if script.Parent.Parent:FindFirstChild("Attachment0Holder") ~= nil then
		   script.Parent.Parent:FindFirstChild("Attachment0Holder"):Destroy()
	    end
	end
end)	
-- end

the notes is what I want to happen but it doesn't work when I do that

2 answers

local hum = script.Parent.Parent:FindFirstChild("Humanoid")
-- if script.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
hum:GetPropertyChangedSignal("Jump"):Connect(function()
    if hum.Jump == true then
        if script.Parent.Parent:FindFirstChild("Attachment0Holder") ~= nil then
           script.Parent.Parent:FindFirstChild("Attachment0Holder"):Destroy()
        end
    end
end)    
-- end

Remove the GetPropertyChangedSignal use .Changed instead. example:

Humanoid.Changed:Connect(function(property)
	if property == "Jump" then
		print("Jump")
	end
end)

or just take this lol

local hum = script.Parent.Parent:FindFirstChild("Humanoid")
-- if script.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
hum.Changed:Connect(function(property)
	if property == "Jump" then
		if hum.Jump == true then
			if script.Parent.Parent:FindFirstChild("Attachment0Holder") ~= nil then
				script.Parent.Parent:FindFirstChild("Attachment0Holder"):Destroy()
			end
		end
	end
end)    
-- end

1 comment

0

This has the same outcome. It tries to check for a humanoid in backpack but I need it to only get the function when it is in the player

try doing this:

local hum = script.Parent.Parent:FindFirstChild("Humanoid")

if not hum then return end -- if doesn't find humanoid then it will do nothing by returning nothing.

hum:GetPropertyChangedSignal("Jump"):Connect(function()
	if hum.Jump == true then
		if script.Parent.Parent:FindFirstChild("Attachment0Holder") ~= nil then
			script.Parent.Parent:FindFirstChild("Attachment0Holder"):Destroy()
		end
	end
end)  

This discussion is preserved as it was. New answers, comments, and votes are closed.