Ok so I have 2 scripts. 1 a local inside a tool that fires info via remote event to a server script that makes parts and deals damage. These 2 scripts make up a fireball that shoots out. The scripts work, but there is an error message that plays which lags the script a bit and makes the fireball a bit glitchy. Its not a major issue though its annoying and not really sure how to fix it.
The error message:
ServerScriptService.NormalSpellDamage:21: attempt to index nil with ‘CFrame’
Local script, locate inside the tool:
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local canshoot = true
local event = game.ReplicatedStorage.NormalSpellEvents.Fireball
local event2 = game.ReplicatedStorage.NormalSpellEvents.Fireball2
local boomy = script.Parent.BallBoom
local boom = Instance.new("Explosion")
local newCFrame = root.CFrame
boom.BlastRadius = 3
ball = nil
fire = nil
function OnActivation()
event:FireServer()
if canshoot == true then
canshoot = false
print('Activation works')
event:FireServer(root,boom, player, boomy)
wait(1)
canshoot = true
end
end
tool.Activated:Connect(OnActivation)
The server script, located in serverscriptservice:
local storage = game.ReplicatedStorage
local fireevent = storage.NormalSpellEvents.Fireball
local function onActivation(Player1, root, boom, player, boomy)
local ball = Instance.new("Part")
ball.Shape = Enum.PartType.Ball
ball.Color = Color3.new(1, 0.333333, 0)
ball.Size = Vector3.new(2,2,2)
ball.Material = Enum.Material.Granite
ball.CanCollide = false
local fire = Instance.new("Fire")
fire.Parent = ball
ball.Parent = root
local newCFrame = root.CFrame
local cf = ball.CFrame
ball.CFrame = newCFrame
local Velocity = Instance.new("BodyVelocity")
Velocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
Velocity.Velocity = ball.CFrame.lookVector * 30
Velocity.Parent = ball
ball.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and hit.Parent ~= player.Character then
local humanoid1 = hit.Parent:FindFirstChild('Humanoid')
humanoid1:TakeDamage(50)
local boom = Instance.new("Explosion")
boom.Parent = ball
boom.Position = ball.Position
boom.BlastPressure = 500
boom.BlastRadius = 3
boom.ExplosionType = "NoCraters"
boom.DestroyJointRadiusPercent = 0
ball.CanCollide = false
ball.CanTouch = false
ball.Transparency = 1
fire:Destroy()
end
end)
ball.Touched:connect(function(hit)
if hit:IsA("Part") and hit.Parent ~= player.Character then
local boom = Instance.new("Explosion")
boom.Parent = ball
boom.Position = ball.Position
boom.BlastPressure = 500
boom.BlastRadius = 3
boom.ExplosionType = "NoCraters"
boom.DestroyJointRadiusPercent = 0
ball.CanCollide = false
ball.CanTouch = false
ball.Transparency = 1
fire:Destroy()
local sound = boomy
sound:Play()
end
end)
end
fireevent.OnServerEvent:Connect(onActivation)
local storage = game.ReplicatedStorage
local fireevent2 = storage.NormalSpellEvents.Fireball2
Ive tried to define newcframe in the local script and fire it off to the serverscript but that caused the fireball’s direction definers too not work.