Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I put GetPropertyChangedSignal in an if statement?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
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
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 GameStealerKid 79 — 3y
Ad
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

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)  

Answer this question