I have a spell in my game that sets the target on fire when you click them, but I have an error
When I click, it errors with Attempt to index nil with 'IsA'
. This error shows if i click on terrain or an object
Heres the script
local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local fireevent = game.ReplicatedStorage.Spells
local spell = false
local loadedSpell = player:WaitForChild("LoadedSpell")
player.Chatted:Connect(function(msg)
if string.lower(msg) == "ignis" and debounce == false and spell == false and player.Character.Ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 and player:FindFirstChild("Pyrokinesis") and loadedSpell.Value == "None" then
spell = true
loadedSpell.Value = "Ignis"
end
end)
mouse.Button1Down:Connect(function()
local mousetarg = mouse.Target
if mouse.Target:IsA("BasePart") then -- errors here
if mouse.Target.Parent:FindFirstChild("Humanoid") and debounce == false and spell == true and player.Character.Ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 and player:FindFirstChild("Pyrokinesis") and loadedSpell.Value == "Ignis" then
debounce = true
if (mousetarg.Position - root.Position).magnitude <25 and debounce == true then
fireevent:FireServer("Ignis", mousetarg)
loadedSpell.Value = "None"
wait(15)
spell = false
debounce = false
end
end
end
end)