Problem with my projectile

So I made a script where when my projectile touches a part, it clones a Hit effect into where the projectile landed. No errors were written in my output but my Hit effect doesn’t show up in workspace. I tried resolving this problem myself yet it just shows errors and stuff.

Here is the code I wrote. Mainly the Hit Effect one

Projectile.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
			if not hit.Parent.Humanoid:FindFirstChild(plr.Name) then
				hit.Parent.Humanoid:TakeDamage(Damage)
			end
			Projectile:Destroy()
		end
		if hit.Parent:FindFirstChild("BasePart") and hit.Parent.Name ~= plr.Name then
			if not hit.Parent:FindFirstChild("Humanoid") then
				local XD = game.ServerStorage.FireMagic.HitFX:Clone() XD.Parent = workspace XD.CFrame = Projectile.CFrame
				Projectile:Destroy()
			end
		end
	end)
1 Like

A good chance why it isnt working is probably because your referring to a CFrame of an object that gets destroyed instantaneously right after, I wonder if you implement Debris | Roblox Creator Documentation and add a short wait parameter it’ll work out as intended.

Try making a variable to store the CFrame value

if hit.Parent:FindFirstChild("BasePart") and hit.Parent.Name ~= plr.Name then
	if not hit.Parent:FindFirstChild("Humanoid") then
		local Hit_CFrame = Projectile.CFrame 
		local XD = game.ServerStorage.FireMagic.HitFX:Clone() 
			XD.Parent = workspace 
			XD.CFrame = Hit_CFrame 

			Projectile:Destroy()
	end
end
1 Like

Hit_Cframe :flushed: Real variable hours

1 Like

How is player defined? Remember in server scripts “game.Players.LocalPlayer” isn’t defined.

local projectile = script.Parent
local players = game:GetService("Players")
local damage = 10
local rs = game:GetService("ReplicatedStorage")
local fire = rs:WaitForChild("FireMagic")
local hitfx = fire:WaitForChild("HitFX")

projectile.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = players:GetPlayerFromCharacter(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:TakeDamage(damage)
		task.wait(1)
		projectile:Destroy()
	elseif not hit.Parent:FindFirstChild("Humanoid") then
		local XD = hitfx:Clone()
		XD.Parent = workspace
		XD.CFrame = projectile.CFrame
		task.wait(3)
		projectile:Destroy()
	end
end)

I’ve moved HitFX to the ReplicatedStorage folder and made some other minor changes.