I am making a projectile that will anchor itself when it hits a wall or the ground.
I am clueless to how to achieve this,I used if hit.Classname == “Part” but it didnt work.
My code:
local sword2 = script.NoblePhantasms.Sword1:Clone()
sword2.CFrame = sword1.CFrame
sword2.Anchored = false
sword2.Transparency = 0
sword2.Material = “Metal”
sword2.Parent = game.Workspace
sword2.ParticleEmitter2.Enabled = false
sword2.Color = Color3.new(0.45098, 0.45098, 0.45098)
sword2.Trail.Enabled = true
local bv = Instance.new("BodyVelocity",sword2)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = ((extra1 - sword2.Position).unit) * 100
sword2.CFrame = CFrame.lookAt(sword2.Position,extra1)
sword2.Orientation = sword2.Orientation + Vector3.new(-90,-360,360)
bv.Name = "Force"
sword1:Destroy()
game.Debris:AddItem(sword2,10)
local debounce = false
sword2.Touched:Connect(function(hit)
if hit.Parent.Humanoid and debounce == false then
if hit.Parent.Name == player.Name then return end
if hit.Parent == game.Workspace then sword2.Anchored = true
end
if hit.Parent:FindFirstChild("Iframes") then
return
end
sword2:Destroy()
local StunHandler = require(game.ReplicatedStorage.StunHandlerV2)
StunHandler.Stun(hit.Parent.Humanoid, 0.3, hit.Parent.CanAttack)
local stun = game.ReplicatedStorage.ExtraFolder.StunnedBillBoard:Clone()
stun.Parent = hit.Parent.Head
game.Debris:AddItem(stun,0.3)
hit.Parent.Humanoid:TakeDamage(8)
local hiteffect = script.SlashParticleKeeper.HitEffect2:Clone()
hiteffect.Parent = hit.Parent.HumanoidRootPart
hiteffect.HitEffect:Emit(1)
hiteffect.Lines:Emit(1)
game.Debris:AddItem(hiteffect,1)
debounce = true
end
end)
The projectiles I want is something like this (King of Heroes) The Roblox Gilgamesh Experience - YouTube