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

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

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 comment

1

hit.Parent.Humanoid.Health = 0 line 3 :P

2 answers

✓ Accepted answer

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)

Fix: Use CFrame rather than position

1 comment

0

as great as the answers above are the fix was literally to use cframe lmao

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