Fireball script error

I was following a tutorial by (HowToRoblox,Fireball script) and when i got to the second section of the CreateFireballScript i started getting error and theirs also another error I am unaware of.The first error is located at line 33 and the second problem will be shown in screenshots
CreateFireBallScript Code:

local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("OnFireBallThrown")-- this gets the remote event parented to replicated storage this is how we recive messagees from the client

local plrsOnCoolDown = {}--This is a table that will contain all the players taht are on cooldown from using the fireball attack 


local ts = game:GetService("TweenService")--this is how we make the fireball move 

ReplicatedStorage.OnServerEvent:Connect(function(plr,mouseCF,camcF)
	if plrsOnCoolDown[plr] then return end--here we check is player is in cooldown Table if so we return stopping the function
	plrsOnCoolDown[plr] = true-- here we add the player to cooll down letting the script know they are on cooldown

	local hrp = plr.Character:WaitForChild("HumanoidRootPart")

	local cf = CFrame.new(hrp.Position , mouseCF.Position)

	local newPos = cf.LookVector * 10000

	local fireball = script:WaitForChild("FireBall"):Clone()
	fireball.CFrame = cf

	local tweenTime = (hrp.Position - newPos).Magnitude / 100

	local ti = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

	local tween = ts:Create(fireball,ti,{Position = newPos})
	tween:Play()

	tween.Completed:Connect(function()
		fireball:Destroy()
	end)	
end)

33. fireball.Touched:Connect(function(hit)
	if hit.Parent~= plr.Character then
		
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(30)
			
			local fire = {}
			for i, child in pairs(hit.Parent:GetChildren()) do
				if child:IsA("BasePart") then 
					local fire = Instance.new("Fire",child)
					
					table.insert(fires,fire)
				end
			end
			
			
			spawn(function()
				
				for i = 1, math.random(5,10) do 
					
					hit.Parent.Humanoid:TakeDamage(5)
					
					wait(1)
				end
				
				for i, fire in pairs(fires) do 
					fire:Destroty()
				end
			end)
		end
		
		fireball:Destory()
	end
end)

fireball.Parent = workspace

wait(1)

plrsOnCoolDown[plr] = nil

Detect Fireball Script:

local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("OnFireBallThrown")--Here we get the RemoteEvent Parented to Replicated storage.Thisis how we will tell the server make a fireball

local mouse = game.Players.LocalPlayer:GetMouse() --This will get the mouse of the player witch we need inorder to tell the fireball where to go 

local cam = workspace.CurrentCamera

local UserInputService = game:GetService("UserInputService")-- We get user Input service witch is how we will tell when the hotkey is activate the fireball attack is pressed


UserInputService.InputBegan:Connect(function(input, processed)
	if processed then return end
	
	if input.KeyCode == Enum.KeyCode.G then 
		
		ReplicatedStorage:FireServer(mouse.hit, cam.CFrame)
	end
end)

Screen shot of error message at line 33:


Weird orange line under text saying that this code is unknown global

Me declaring variables:

Detect Fireball Script

It seems that in your CreateFireBall script, fireball isn’t defined. Did you declare and assign the variable fireball? If so, are you sure your variable declaration is in the correct scope?

2 Likes

That’s because the fireball.Touched event is not inside the .OnServerEvent function thingy.

Simply do this:

local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("OnFireBallThrown")-- this gets the remote event parented to replicated storage this is how we recive messagees from the client

local plrsOnCoolDown = {}--This is a table that will contain all the players taht are on cooldown from using the fireball attack 


local ts = game:GetService("TweenService")--this is how we make the fireball move 

ReplicatedStorage.OnServerEvent:Connect(function(plr,mouseCF,camcF)
	if plrsOnCoolDown[plr] then return end--here we check is player is in cooldown Table if so we return stopping the function
	plrsOnCoolDown[plr] = true-- here we add the player to cooll down letting the script know they are on cooldown

	local hrp = plr.Character:WaitForChild("HumanoidRootPart")

	local cf = CFrame.new(hrp.Position , mouseCF.Position)

	local newPos = cf.LookVector * 10000

	local fireball = script:WaitForChild("FireBall"):Clone()
	fireball.CFrame = cf

	local tweenTime = (hrp.Position - newPos).Magnitude / 100

	local ti = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

	local tween = ts:Create(fireball,ti,{Position = newPos})
	tween:Play()

	tween.Completed:Connect(function()
		fireball:Destroy()
	end)	


fireball.Touched:Connect(function(hit)
	if hit.Parent~= plr.Character then
		
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(30)
			
			local fire = {}
			for i, child in pairs(hit.Parent:GetChildren()) do
				if child:IsA("BasePart") then 
					local fire = Instance.new("Fire",child)
					
					table.insert(fires,fire)
				end
			end
			
			
			spawn(function()
				
				for i = 1, math.random(5,10) do 
					
					hit.Parent.Humanoid:TakeDamage(5)
					
					wait(1)
				end
				
				for i, fire in pairs(fires) do 
					fire:Destroty()
				end
			end)
		end
		
		fireball:Destory()
	end
end)

fireball.Parent = workspace

wait(1)

plrsOnCoolDown[plr] = nil
end)           --this is the end for the ReplicatedStorage.OnServerEvent

Just copy and paste it if u want.

Thank you for replying now i have another articel i can read and learn from :slight_smile:

it works but now there is another error

local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("OnFireBallThrown")-- this gets the remote event parented to replicated storage this is how we recive messagees from the client

local plrsOnCoolDown = {}--This is a table that will contain all the players taht are on cooldown from using the fireball attack 


local ts = game:GetService("TweenService")--this is how we make the fireball move 

ReplicatedStorage.OnServerEvent:Connect(function(plr,mouseCF,camcF)
	if plrsOnCoolDown[plr] then return end--here we check is player is in cooldown Table if so we return stopping the function
	plrsOnCoolDown[plr] = true-- here we add the player to cooll down letting the script know they are on cooldown

	local hrp = plr.Character:WaitForChild("HumanoidRootPart")

	local cf = CFrame.new(hrp.Position , mouseCF.Position)

	local newPos = cf.LookVector * 10000

	local fireball = script:WaitForChild("FireBall"):Clone()
	fireball.CFrame = cf

	local tweenTime = (hrp.Position - newPos).Magnitude / 100

	local ti = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

	local tween = ts:Create(fireball,ti,{Position = newPos})
	tween:Play()

	tween.Completed:Connect(function()
		fireball:Destroy()
	end)	


	fireball.Touched:Connect(function(hit)
		if hit.Parent~= plr.Character then

			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid:TakeDamage(30)

				local fire = {}
				for i, child in pairs(hit.Parent:GetChildren()) do
					if child:IsA("BasePart") then 
						local fire = Instance.new("Fire",child)

						table.insert(fires,fire)
					end
				end


				spawn(function()

					for i = 1, math.random(5,10) do 

						hit.Parent.Humanoid:TakeDamage(5)

						wait(1)
					end

					for i, fire in pairs(fires) do 
						fire:Destroty()
					end
				end)
			end

			fireball:Destory()
		end
	end)

	fireball.Parent = workspace

	wait(1)

	plrsOnCoolDown[plr] = nil
end)           --this is the end for the ReplicatedStorage.OnServerEvent

at line 53 this error pops up

in line 39 change:

local fire = {}

To:

local fires = {} 

Just a small misspell

1 Like

My bad i sent the wrong code i correct that silly spelling error i made and I spelled Destroy wrong lol here’s the new code i am having problems with

local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("OnFireBallThrown")-- this gets the remote event parented to replicated storage this is how we recive messagees from the client

local plrsOnCoolDown = {}--This is a table that will contain all the players taht are on cooldown from using the fireball attack 


local ts = game:GetService("TweenService")--this is how we make the fireball move 

ReplicatedStorage.OnServerEvent:Connect(function(plr,mouseCF,camcF)
	if plrsOnCoolDown[plr] then return end--here we check is player is in cooldown Table if so we return stopping the function
	plrsOnCoolDown[plr] = true-- here we add the player to cooll down letting the script know they are on cooldown

	local hrp = plr.Character:WaitForChild("HumanoidRootPart")

	local cf = CFrame.new(hrp.Position , mouseCF.Position)

	local newPos = cf.LookVector * 10000

	local fireball = script:WaitForChild("FireBall"):Clone()
	fireball.CFrame = cf

	local tweenTime = (hrp.Position - newPos).Magnitude / 100

	local ti = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

	local tween = ts:Create(fireball,ti,{Position = newPos})
	tween:Play()

	tween.Completed:Connect(function()
		fireball:Destroy()
	end)	


	fireball.Touched:Connect(function(hit)
		if hit.Parent~= plr.Character then

			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid:TakeDamage(30)

				local fires = {}
				for i, child in pairs(hit.Parent:GetChildren()) do
					if child:IsA("BasePart") then 
						local fire = Instance.new("Fire",child)

						table.insert(fires,fire)
					end
				end


				spawn(function()

					for i = 1, math.random(5,10) do 

						hit.Parent.Humanoid:TakeDamage(5)

						wait(1)
					end

					for i, fire in pairs(fires) do 
						fire:Destroy()
					end
				end)
			end

line 53

Can u change line 53 to:

if hit.Parent:FindFirstChild("Humanoid") then
     print("Found the humanoid")
     hit.Parent.Humanoid:TakeDamage(5)
end

check if it prints in the output.

1 Like