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

How Do I Prevent a Part From Raising While It's Tweening, While Having a Touched Script?

Asked by 6 years ago

I have a part that I'm moving in a building, an explosion basically. I want it to pass everything, and it does that normally. But when I added the script to kill any players it touches, it goes above the building.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Humanoid.Health = 0
        table.remove(_G.foundplayers, game.Players[hit.Name])
    end
end)

^ in the brick

1
`hit.Parent.Humanoid.Health = 0` line 3 :P TheeDeathCaster 2368 — 6y

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

Simple error. You're attempting to index "Humanoid" from hit rather than hit.Parent. hit is the potential limb that touched, while hit.Parent is the potential Character.

Also, the second argument of table.remove isn't the Value to remove. It is the Index of the value to remove.. you have to loop through the _G.foundplayers table using a generic for loop. Once you find the equivalent value, use table.remove on the given index.

Lastly, connect is deprecated. Use Connect !

function removePlr(p)
    --Iterate through foundplayers
    for index,value in pairs(_G.foundplayers) do
        if value == p then --If current val is equivalent
            --remove by index
            table.remove(_G.foundplayers, index);
        end
    end
end

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        hit.Parent:FindFirstChild("Humanoid").Health = 0;
        removePlr(plr)
    end
end)
Ad
Log in to vote
0
Answered by 6 years ago

Fix: Use CFrame rather than position

0
as great as the answers above are the fix was literally to use cframe lmao BouncingBrenda 44 — 6y

Answer this question