Hello, I’ve been trying o figure out what is the problem with this script but I do not understand what’s going on here. Normal the player should cast a spell like this:
Instead of the black parts damaging the NPC which has a humanoid it does nothing instead. Heres the script:
local tweenservice = game:GetService("TweenService")
game.ReplicatedStorage["Incantations [EVENTS]"]:WaitForChild("VacuusEvent").OnServerEvent:Connect(function(Player)
local Vacuus = game.ReplicatedStorage["Incantations [PARTS]"].VacuusPart:Clone()
Vacuus.Parent = workspace
game.Debris:AddItem(Vacuus,1)
Vacuus.CFrame = Player.Character["Right Arm"].CFrame + Player.Character.HumanoidRootPart.CFrame.lookVector * 1
tweenservice:Create(Vacuus,TweenInfo.new(1,0,0),{CFrame = Player.Character["Right Arm"].CFrame + Player.Character.HumanoidRootPart.CFrame.lookVector * 20,Transparency = 1}, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut):Play()
-- WHEN THE PLAYER TOUCHES 'Vacuus' THEN.
local alreadytouched = false
Vacuus.Touched:Connect(function(hit)
if alreadytouched == true then return end
if hit.Parent.Name == Player.Name then return end
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
end
end)
alreadytouched = true
end)
The promblem lies around here:
local alreadytouched = false
Vacuus.Touched:Connect(function(hit)
if alreadytouched == true then return end
if hit.Parent.Name == Player.Name then return end
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
end
end)
alreadytouched = true
It is a function, which gives (returns) you an array of instances, but you need to create a touch event, which creates a Touchinterest.
Then you can use local TouchingObjects = Part:GetTouchingParts() function
Anchored parts do detect collision? Otherwise killbricks in every single obby wouldn’t work.
Edit: ASCENDED UNDERSTANDING
You probably mean it’s because the other parts aren’t moving, because it only detects physics collisions. They do detect collision though, but only if the other parts are unanchored. That’s why obby killbricks work.
It’s probably because it’s not moving with physics. Yes, anchored parts do detect collisions with UNANCHORED parts, but the dummies seem to not be moving.
Try moving it with forces, velocity, or constraints. Then it will probably work.
Just some code recommendations:
Replace Hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Heath - 1 with hit.Parent.Humanoid:TakeDamage(1). This is forcefield friendly, and might prevent spawnkilling.
Replace hit.Parent.Name == Player.Name with game.Players:GetPlayerFromCharacter(hit.Parent) == Player. This is friendly with errors.
local alreadytouched = false -- You set this value to false
Vacuus.Touched:Connect(function(hit)
if alreadytouched == true then return end -- Since you instantly set alreadytouched to true-> the below doesn't run
if hit.Parent.Name == Player.Name then return end
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
end
end)
alreadytouched = true -- The above connection does not yield so this line instantly runs next setting the alreadytouched to true
The issue is you are instantly setting “alreadytouched” to false right after you create the touch connection. I also advise you don’t create touch connections within other connections (unless you plan on disconnecting them).
Honestly, I would prob just destroy the part inside the touch connection instead of using a bool value:
Vacuus.Touched:Connect(function(hit)
if hit.Parent.Name == Player.Name then
return;
end;
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
Vacuus:Destroy(); -- Calling the destroy function disconnects the touch connection and removes the part!
end
end)