Why Wont My Fire Balls Head To The Player's Position?

I am trying to make a tool that spawns a couple of fire balls above the player. When I tried this script out the fireballs spawned, but not above the player, where they are in ReplicatedStorage. Why? There is nothing in the explorer except these things: StarterPack > Tool > Script, and ReplicatedStorage > FireBalls. The Debounce (able) also doesnt work.

local able = true

script.Parent.Activated:Connect(function(player)
	if able == true then
		local PlusPosition = Vector3.new("0,50,0")
		local fireballs = game:GetService("ReplicatedStorage").FireBalls:Clone()
		fireballs.Parent = game.Workspace
		fireballs.PrimaryPart.CFrame = player.Character.HumanoidRootPart.CFrame + PlusPosition
		able = false
		
		wait(5)
		fireballs:Remove()
		able = true
		
	end

end)

4 Likes

Don’t put the Vector3 parameters in quotation marks. This is how you need to do it:
local PlusPosition = Vector3.new(0,50,0)

When dealing with CFrames, you also have to use * instead of + to add onto it. So you should also turn the PlusPosition variable into a CFrame or put CFrame.new(PlusPosition)
And you should replace :Remove() with :Destroy() since :Remove() is deprecated.

1 Like

Oh wait hmm, thats weird. For some reason the quotes arnt there in the script in game.

2 Likes

When working with a cframe you should do it like this instead

fireballs.PrimaryPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position + PlusPosition)

The reason the code isn’t working is because you’re trying to add a vector3 to a cframe

In this case, you want to convert a Vector3 to a CFrame so you just put it inside a CFrame.new()

2 Likes

One second, im testing but i’ll tell you if it works or not

2 Likes

Hmm thats strange it still doesnt seem to work! here is the code now that it’s updated:

local able = true

script.Parent.Activated:Connect(function(player)
	if able == true then
		local PlusPosition = Vector3.new(0,50,0)
		local fireballs = game:GetService("ReplicatedStorage").FireBalls:Clone()
		fireballs.Parent = game.Workspace
		fireballs.PrimaryPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position + PlusPosition)
		able = false

		wait(5)
		fireballs:Remove()
		able = true

	end

end)
2 Likes

Since you said you wanted it to spawn above the player, I suggest you try this:

fireballs.PrimaryPart.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,5,0)

or this if it is a model:

fireballs:PivotTo(player.Character.HumanoidRootPart.CFrame * CFrame.new(0,5,0))

adjust the CFrame to your preference of course.

2 Likes

Its most likely then something to do with the primarypart, maybe somethings not right with the model.

2 Likes

Thats so strange It still doesnt want to work. I wonder why its doing this.

2 Likes

Are there any errors in your console?
Edit: And do you even have a PrimaryPart set?

2 Likes

Yes, it says this:’

Players.will_nc.Backpack.Tool.Script:8: attempt to index nil with 'Character'
2 Likes

Ah, just noticed player isn’t a parameter of the function Activated. Try to declare player like this inside of your activated function (and remove player from your function parameters):

local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

3 Likes

Yes it worked! Thank you so much! this was very helpful!

2 Likes

Glad I could help, you’re welcome :slight_smile:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.