So im trying to make a script that throws a fireball and stops the player while doing so. This is the script i have. I think the reason why its not working is because it says that Plugin_142731176._Char:93: attempt to index global 'character' (a nil value) and im not sure how to define it. Also, when i do this, the fireball does not fire anymore, and when i press r, its just the animation of the fireball being thrown. Here is the script.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RemoteEvent = game.Workspace.Fired
local UIS = game:GetService("UserInputService")
local parts = Player.Character:GetChildren()
local Debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.R then
wait (0.5)
if Debounce == true then return end
for i = 1, #parts do
if (parts[i].ClassName == "MeshPart") then
parts[i].Anchored = true
end
end
Anchored = false
RemoteEvent:FireServer(Debounce)
end
end)
This is the server code for the remote event
game.Workspace.Fired.OnServerEvent:Connect(function(Player, Debounce)
local AlreadyTouched = false
local Character = Player.Character or Player.CharacterAdded:wait()
Debounce = true
local Fireball = Instance.new("Part")
Fireball.Name = "Fireball"
Fireball.Shape = Enum.PartType.Ball
Fireball.Size = Vector3.new(3,3,3)
Fireball.Material = Enum.Material.Neon
Fireball.BrickColor = BrickColor.new("Deep orange")
Fireball.CanCollide = false
Fireball.Parent = Character
Fireball.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0,1,-6)
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = Character.HumanoidRootPart.CFrame.lookVector*100
BV.Parent = Fireball
--adding fire
local Fire = Instance.new("Fire")
Fire.Parent = Fireball
Fire.Heat = (5)
Fire.Size = (10)
Fireball.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if AlreadyTouched == false then
AlreadyTouched = true
if Humanoid.Parent == Character then
Humanoid.Health = Humanoid.Health - 0
else
Humanoid.Health = Humanoid.Health - Humanoid.MaxHealth/4
end
end
end)
wait(2)
Fireball:Destroy()
Debounce = false
end)

7 comments
uhh.. set the walkspeed to 0?
You shouldn’t be wrapping your if statements in brackets at line 14. Remove them.
yes, that could work but i am not sure how to exactly do that.
Can you post the Server code for the remote event?
alright i edited it
make which player stop? the player shooting the fireball or the player being hit by the fireball?
the player shooting the fireball