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

why wont this this script execute when player isnt touching the part anymore???

Asked by 6 years ago

I attempted to make it so when the player gets off the block it prints "not touching anymore" but it does not print

I decided to try this because the .TouchedEnded event is trash and doesnt work all the time ;(

script.Parent.Touched:connect(function(hit)
    if hit.Parent:WaitForChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        local coins = plr:WaitForChild("leaderstats"):WaitForChild("Coins")
        local candy = plr:WaitForChild("leaderstats"):WaitForChild("Candy")
        touching = true
        CEopen:FireClient(plr)
        while touching do
            wait(1)
            local touchingparts = script.Parent:GetTouchingParts()
            for i,v in pairs(touchingparts) do
                if v.Parent:WaitForChild("Humanoid") == nil then
                    print("not touching anymore")
                end
            end
        end
    end
end)
0
Why don't you try to make a TouchedEnded event? hiimgoodpack 2009 — 6y
0
because its funky, when I use a touch ended event the touched event doesnt always fire, and when it does the touch ended event does not work its weird AWESOMEnoob3 3 — 6y
0
IT IS CAUSE TOUCHING = TRUE THE ENTIRE TIME greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

On line 12 you use WaitForChild. That will actually "block" what you are doing and the script will at that point wait until all children that are touching the part have a Humanoid child.

if v.Parent:WaitForChild("Humanoid") == nil then

You will want to change that to FindFirstChild.

if v.Parent:FindFirstChild("Humanoid") == nil then
Ad

Answer this question