Having problems with a spell script

  1. What do you want to achieve? I want the spell to be able to properly damage all dummies in the region, make the region in the correct position, cast multiple spells without having their regions “broken” and make it basically as fast I want without getting any problems.

  2. Issues:

a: Region not getting all the dummies (https://gyazo.com/ef3a67dab73b9d6c94b8986fa5fcad1c) [Edit] Fixed by increasing region parts detection limit

b: Touched event seems to be firing before the spell actually touches the dummy https://gyazo.com/4ef748025f9659e53e2c1bf6c3491299 [Edit] Fixed by using P:SetNetworkOwner(nil)

c: Whenever the first spell hits something, every region position will be set to the most recent spell position (this happens when more than one spell is used at the same time) https://gyazo.com/50558b34783c47fb8cd7bc8ffdf455dc [Edit] Fixed by placing all the touch detection area of the script inside of another script inside of the projectile (not sure if this is a good way of dealing with this problem tho)

d: Faster spell = more delay before actually start moving
https://gyazo.com/04cff412948340a0b5ef4451c20dc8c9 [Edit] Topic solution

  1. What have I tried: I’ve tried giving the BodyVelocy’s MaxForce a huge number, watched gun tutorials, as they would have high speed projectiles (these had the same weird velocity problem still) and published the game to see if it wasn’t a problem with studio.

This is my setup: 6f3bd31985fd245a3afb2da0b91a0b98

FireBlast has Anchored and CanCollide set to false
BodyVelocity has MaxForce set to a huge number, P to 1250 and Velocity 0,0,0

-- INSIDE ACTIVATOR

UIS = game:GetService("UserInputService")
Player = game.Players.LocalPlayer
repeat wait() until Player.Character
character = Player.Character
Mouse = Player:GetMouse()

Mouse.TargetFilter = workspace.AntiMouse

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == Enum.KeyCode.Q then
		
		script.Remote:FireServer("Projectile",character.HumanoidRootPart.CFrame,Mouse.hit.Position)
	end
end)



-- INSIDE MAIN

-- settings
local DAMAGE = 15
local VELOCITY = 100
local AOE = 6
local COOLDOWN = .1
local PROJECTILE = game.ReplicatedStorage.Projectiles.FireBlast



local enabled = true

script.Parent.OnServerEvent:Connect(function(Player, Action, V1, V2)
	local character = Player.Character

	if Action == "Projectile"  and enabled == true then 
		enabled = false

		P = PROJECTILE:Clone() 
		P.Name = Player.Name.."Projectile"
		P.CFrame = V1*CFrame.new(0,0,-1) 
		P.CFrame = CFrame.new(P.Position, V2) 
		P.Parent = workspace.AntiMouse.Projectiles 
		game.Debris:AddItem(P,10) 
		
		local BV = P.BodyVelocity
		BV.Velocity = P.CFrame.lookVector*VELOCITY
		
		local Trigger = true 
		P.Touched:connect(function(hit)
			if Trigger == true and hit.Parent.ClassName ~= "Accessory" and hit.Parent ~= character and hit.Name ~= Player.Name.."Projectile" then
				Trigger = false

				P.Anchored = true
				game.Debris:AddItem(P,.1)
				
				
				
				local region = Region3.new(P.Position - Vector3.new(AOE,AOE,AOE), P.Position + Vector3.new(AOE,AOE,AOE)) -- pega a posição do projetil, ai diminui e aumenta em um mesmo valor, fazendo um cubo/região
				local parts = workspace:FindPartsInRegion3(region, character)
				
				-- makes area of effect visible
				local area = Instance.new("Part")
				area.Parent = workspace.AntiMouse.FX
				area.Size = region.Size
				area.Position = P.Position
				area.CanCollide = false
				area.Transparency = 0.8
				area.Anchored = true
				game.Debris:AddItem(area, 3)

				for _, v in ipairs(parts) do
					local Humanoid = v.Parent:FindFirstChild("Humanoid")
					if v.Name == "HumanoidRootPart" and Humanoid then

						Humanoid.Health = Humanoid.Health - DAMAGE
					end
				end
			end
		end)
		
		wait(COOLDOWN)
		enabled = true	
	end
end)

This is my first topic, sorry if it wasn’t properly made.

1 Like

Your topic is well written and it’s good to see you have updated it with the progress you have made. Sorry I can’t assist but a bump might get someone else to notice the thread

I’m guessing the delay is caused by the network delay as the server has to entirely create a new projectile and replicate it to the client whenever the even is received. Perhaps you can cut the delay by making the projectile before hand and hence saving steps using this buffer technique.

2 Likes