My goal is to kill the player when the tile falls down and hits them.
Currently I am using a touched event to signal when the player touches the ‘kill_Part’ that is welded to the tile.
local function touched_Kill_Part(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "HumanoidRootPart" then
local char = hit.Parent
local hum = char.Humanoid
local plr = game.Players:GetPlayerFromCharacter(char)
if hum.Health > 0 then
hum.Health = 0
if plr then
table.remove(players_In_Game, table.find(players_In_Game, plr))
end
end
end
end
local kill_Part = Instance.new("Part")
-- add weld constraint
local weld = Instance.new("WeldConstraint")
weld.Parent = kill_Part
weld.Part0 = kill_Part
weld.Part1 = tile
--
kill_Part.Transparency = 0.5
kill_Part.CanCollide = false
kill_Part.Anchored = false
kill_Part.BrickColor = BrickColor.Yellow()
kill_Part.CastShadow = false
--
kill_Part.Size = Vector3.new(30, 2, 30)
kill_Part.CFrame = CFrame.new(tile.Position.X, tile.Position.Y - tile.Size.Y/2 - kill_Part.Size.Y/2, tile.Position.Z)
kill_Part.Parent = tile
-- connecting kill part to the kill function
kill_Part.Touched:Connect(touched_Kill_Part)
twe_Service:Create(tile, TweenInfo.new(speed, Enum.EasingStyle.Quint, Enum.EasingDirection.In), {CFrame = CFrame.new(pos.Position.X, pos.Position.Y - pos.Size.Y/2 + extra + tile.Size.Y/2, pos.Position.Z)}):Play()
Just ignore the tile and other stuff and just picture that there is a part with another part welded to the bottom and will fire the ‘touched_Kill_Part’ function when touched. You might like to know that I am moving the tile by tweening it to the desired position where it will land on the tower. Let me know if there’s a better way of doing this.
In my situation I thought touched event would be fine as the tile just falls from the sky so it seems pretty simple. However the touched event is so unreliable and I would like to try and do it another way.
What other ways do you suggest I go about this?
Any feedback/help is appreciated.
(Also here is a screenshot so you can visualise what the tile looks like)