so, i am recently making a hitbox to when the player touches then he dies.
i programmed it so it can olny be triggered by a player, and for some reason, touch events does not fires.
local Part = script.Parent
Part.Touched:Connect(function(part)
print(script.Parent.Name, Part)
local P = game.Players:GetPlayerFromCharacter(part.Parent)
if P then
local MonsterScript = require(Part.Parent:FindFirstChild("MonsterScript"))
if MonsterScript then
MonsterScript.Kill(P)
end
end
end)
note that the enemy needs to clone the hitbox, then weld it to kills
here is a example
local Hitbox = game.ReplicatedStorage.JumpscareHitboxes.BigJumpscareHitbox:Clone()
Hitbox.Parent = Monster
local Weld = Instance.new("Weld")
Weld.Parent = Hitbox
Weld.Part0 = Monster.Effects
Weld.Part1 = Hitbox
the script local and clones the hitbox, then he parents to itself, it makes a weld between the main part and the hitbox itself to “anchor” the part
when player touches the hitbox, that function must be callen from a module script
function ms.Kill(Player)
print("Killed ", Player)
end
CanTouch allows touched events to fire on that item.
If you have it set to false it’ll save some CPU lag because it won’t be checking to see if those components are ever touching anything.
it was on before, since i don,t use CanCollide to check if a part is touching or not, for some reason, the SafeZone Hitbox works perfectly, but not the kill hitbox
he it is:
local SavenFF
local function GiveForceField(p)
local FFLocal = p.Character:FindFirstChild("SafeFF")
if not FFLocal then
local FF = Instance.new("ForceField")
SavenFF = p.Character.Humanoid.Health
p.Character.Humanoid.Health = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
FF.Parent = p.Character
FF.Name = "SafeFF"
FF.Visible = false
end
end
local function RemoveForceField(p)
p.Character.Humanoid.Health = SavenFF
local FF = p.Character:FindFirstChild("SafeFF")
if FF then
FF:Destroy()
end
end
local Part = script.Parent
Part.Touched:Connect(function(part)
local P = game.Players:GetPlayerFromCharacter(part.Parent)
if P then
GiveForceField(P)
end
end)
Part.TouchEnded:Connect(function(part)
local P = game.Players:GetPlayerFromCharacter(part.Parent)
if P then
RemoveForceField(P)
end
end)
its kinda different since it uses functions when player is touching or not, but it have the same purpose