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

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

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

3 comments

0

KeyDown is Deprecated.Instead,use UserInputService and InputBegan.

0

why are you changing the position first and then the CFrame?

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.

1 answer

✓ Accepted answer

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

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