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
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