Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

A script meant to launch a fireball isn't working, but no errors appear when i run it?

Asked by
Zzverot 16
5 years ago

I'm making a game where if you press 'F' you launch a fireball. This is the script i'm using

game.Players.PlayerAdded:wait()
Player = script.Parent.Parent.Parent -- Gets LocalPlayer 

Player.CharacterAdded:wait()
Character = Player.Character

Mouse = Player:GetMouse()

function onKeyDown(key) 
    if key:lower() == "f" then 
        local ball = Instance.new("Part") 
        ball.TopSurface = "Smooth" 
        ball.BottomSurface = "Smooth" 
        ball.Shape = "Ball" 
        ball.Transparency = 0.7
        ball.BrickColor = BrickColor.new("Bright red") 
        ball.Parent = game.Workspace 

        local fire = Instance.new("Fire") 
        fire.Parent = ball 
        fire.Size = 12 
        fire.Heat = 0 
        fire.Color = BrickColor.new("Really black")

        local velocity = Instance.new("BodyVelocity") 
        velocity.maxForce = Vector3.new(999, 999, 999)
        velocity.velocity = Character.Head.CFrame.lookVector * 50
        velocity.Parent = ball  

        ball.Position = Character.Head.Position + 2
        ball.CFrame = Character.Head.CFrame * CFrame.new(0, 0, 10)
    end 
end 

Mouse.KeyDown:connect(onKeyDown)
-- this is placed in a tool inside the starter pack

it doesn't show any errors when i run it, but it doesn't work Can anyone explain what the problem is? I'm pretty new to roblox lua scripting, so sorry if this is a stupid question

0
KeyDown is Deprecated.Instead,use UserInputService and InputBegan. rochel89 42 — 5y
0
why are you changing the position first and then the CFrame? ScrubSadmir 200 — 5y
0
:connect() is outdated. Use it with capital, :Connect(). I would also consider using UserInputService rather than the mouse to detect when the player presses a button. Also, game.Workspace is an old method. You can just type workspace. BrickColors are kinda old, but still usable. jharnekus 3 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The reason this is not working is that you are trying to create a part from the Client which doesn't work because Filtering is enabled meaning all changes the client makes dont replicate to the server and vice versa, you'll have to use Remote Events/Functions (highly recomend Events for this as Events are one way and Functions yield the script which you don't want in a script like this and expect an answer from the receiver and are used mostly to get an object or value from the boundary).

Here's a link to a video which explains Remote Events quite well and you should check it out: https://www.youtube.com/watch?v=wic-N4JiFss

Ad

Answer this question