Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make it so the player stops in my fireball script?

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

0

uhh.. set the walkspeed to 0?

0

You shouldn’t be wrapping your if statements in brackets at line 14. Remove them.

0

yes, that could work but i am not sure how to exactly do that.

0

Can you post the Server code for the remote event?

0

alright i edited it

0

make which player stop? the player shooting the fireball or the player being hit by the fireball?

0

the player shooting the fireball

1 answer

inbetween lines 4 and 5 in the local script do

local Character = game.Workspace:WaitForChild(Player.Name)

then replace the

local parts = Player.Character:GetChildren()

with

local parts = Character:GetChildren()

replace line 3 in the server script to

local Character = game.Workspace:WaitForChild(Player.Name)

then after line 18 in the server script just do

local defaultspeed = Humanoid.WalkSpeed
local defaultjump = Humanoid.JumpPower
local time = 0.5 -- here put how long you want the stop to be for

Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
wait(time)
Character.Humanoid.WalkSpeed = defaultspeed
Character.Humanoid.JumpPower = defaultjump

This discussion is preserved as it was. New answers, comments, and votes are closed.