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

Anyone know how to script fireball projectiles?

I tried looking at YT and used this local script

local Player = game.Players.LocalPlayer

local rp = game:GetService("ReplicatedStorage") local FireBall = rp:WaitForChild("FireBall")

local UIS = game:GetService("UserInputService") local debounce = false local cooldown = 2

UIS.InputBegan:connect(function(input , isTyping) if isTyping then return elseif input.KeyCode == Enum.KeyCode.E then if debounce == false then debounce = true

		FireBall:FireServer()
	end
end

end)

FireBall.OnClientEvent:Connect(function() wait(cooldown) debounce = false end)

2 answers

This should be pretty simple

Though I won't write code for you these are some links you're probably looking for.

Helpful Links: https://developer.roblox.com/en-us/api-reference/class/Tween https://developer.roblox.com/en-us/api-reference/datatype/CFrame (You could also use Vector3) https://developer.roblox.com/en-us/api-reference/property/Mouse/Target

Using these 3 tools could just about make a fireball, and using your code for a debounce and Imput service detection you should be good to go to use these for a function that creates a fireball.

Try putting the fireball model in replicated storage and using a remote event to clone it and then tween it towards the mouses target.

Localscript, you can put it inside PlayerGui, StarterPack, StarterPlayerScripts, StarterCharacterScripts

local player = game.Players.LocalPlayer -- getting player
local uis = game:GetService("UserInputService") -- getting UserInputService
local db = true

uis.InputBegan:Connect(function(input, playerIsChatting) 
	if input.KeyCode == Enum.KeyCode.E then -- checking is input that player did was letter E
		if not playerIsChatting then -- checking if player wasnt typing 
			if db then -- checking if db(debounce) is true. If false then it cant go through and stops here
				db = false -- db is now false
				workspace.FireballEvent:FireServer() -- firing remoteevent inside rep storage (we need remote event so other players in game can see the fireball)

				wait(5)
				db = true -- after 5 seconds db is true again and player can shoot fireball again

			end
		end
	end
end)

now put RemoteEvent inside Workspace and Server side script (normal script) inside RemoteEvent

Server script

script.Parent.OnServerEvent:Connect(function(player) 
	local fireBall = game.ReplicatedStorage.Ball:Clone() -- making path to Fireball inside rep storage and also cloning it

	-- make sure fireball isnt anchored
	
	local char = player.Character or player.CharacterAdded:Wait() -- waiting for players Character
	local HRP = char:WaitForChild("HumanoidRootPart") -- waiting for HumanoidRootPart. good thing is that HumanoidRootPart has r6 and r15 avatars
	
	fireBall.Parent = workspace -- new parent is now workspace
	fireBall.Position = HRP.Position -- fireball position is now at center of HumanoidRootPart
	
	local bodyV = Instance.new("BodyVelocity", fireBall) 
	bodyV.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- setting max force to vector3 math.huge... (math.huge is infinity so it wont fall down)

	bodyV.Velocity = HRP.CFrame.LookVector * 120 -- direction where fireball will go, HRP.CFrame.LookVector is where the hrp is looking (Front Surface)
	
	local hitDb = true
	fireBall.Touched:Connect(function(hit)

		if hit:IsA("BasePart")then -- if fireball doesnt hit accessory or something like that
			if not hit:IsDescendantOf(char) then -- if hit isnt part inside character so we cant damage us

				if hitDb then -- if db is true than it can go if false then it cant do damage
					hitDb = false
				
				if hit.Parent:FindFirstChild("Humanoid") then -- hit can be Arm or Head so we want Parent of that part so that will be players Character, now we are checking if hit.Parent have Humanoid

						local Ehum = hit.Parent.Humanoid 
						fireBall:Destroy() -- if hit player it will destroy fireball
							Ehum:TakeDamage(20) -- if yes, we can deal him damage
					end
				end
			end
		end
	end)
	
	wait(5)
	
	fireBall:Destroy() -- fireball will destroy after 5 seconds
	hitDb = true -- hitDb is true so fireball can damage again
end)

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