I need YOUR help! yes you!

so im making a game where u cna shoot fire balls. Heres my current code but like it doesnt work, its supposed to be like the balll will fire in the direction the right or left hand is pointed at. im new to luau so yeah

local rp = game.ReplicatedStorage
local remote = rp:WaitForChild("FireSpell")
local ball = script.Ball

ball:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))

remote.OnServerEvent:Connect(function(player, position)
	local name = player
	local ballClone = ball:Clone()
	local playerName = tostring(player.Name)


	if not ballClone.PrimaryPart then
		ballClone:SetPrimaryPart(ballClone:WaitForChild("PrimaryPart"))
	end

	if name.Way.Value == "Right" then
		local pos = script.Parent.CFrame
		ballClone:SetPrimaryPartCFrame(pos)
		script.Parent = game.Workspace:FindFirstChild(playerName).RightHand

	else
		local pos2 = script.Parent.CFrame
		ballClone:SetPrimaryPartCFrame(pos2)
		script.Parent = game.Workspace:FindFirstChild(playerName).LeftHand

	end

	local direction = ballClone.PrimaryPart.CFrame.LookVector
	local velocity = 5

	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.Velocity = direction * velocity
	bodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)  
	bodyVelocity.Parent = ballClone.PrimaryPart

	wait(3)
	ballClone:Destroy()
end)

id love to receive any help!
(and yes ive confirmed the remotes and stuff does run)

4 Likes

I need more info, like is there an output, where is the script located?

2 Likes

ServerStorage and inside of the script theres the ball

1 Like

(but it does get cloned as a child to the weapon when the remotevent happens so eveyrhting is up and runnin its just this code doesnt work)

I don’t think you parented the ball clone to anything

1 Like

Well the ball is placed inside of the script and yeha in the if it == right itll set the scripts parent which will do with the ball the same.

Sorry, what do you mean by that? I don’t see any line that sets the parent.

The ball kinda has to be in Workspace to be seen. That is your issue.

Well it is a child of the playersmodel in workspace’s left hand sooooooo yeah

its there and ive checked during the game and yes it is praneted ti the right hand

I don’t see that in your code. You need to explicitly set the Parent property for this cloned part

local ballClone = ball:Clone()

Which you do not do.

i think you should put the script in replicated storage idk if that will help but it might

i meant replicated storage whoop idk it the comment will edit so here is a new one

the only difference by putting it in replicated storage instead of serverstorage will be that the client can access it as well so i dont see any point in that

the ball is placed inside of the script and again, ive checked during gameplay and it is parented to the right hand

Like guys rn if anyone has an alternative code and setup than mine id gladly appreciate it

Please show me where in the script this takes place for the cloneball. The clone exists in memory onl;y until it is parented to something within the game, ie the workspace.

The process as I see it should be:

  1. Clone ball
  2. Create velocity, parent to clone ball
  3. Parent clone ball to workspace
  4. Debris clone ball after x seconds or on hit event.

it is parented to the right hand of my player

image_2024-01-02_123256652

OK, so if that is a screenshot of the script in action, why do I not see both the original script.Ball part and also the ballClone part. I see only one instance.

As I said previosuly, when you clone an object, it exists in memory only. It does not exist in the game until it is parented.

Try the following near the end of your script where the BV is created:

	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.Velocity = direction * velocity
	bodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)  
	bodyVelocity.Parent = ballClone.PrimaryPart
	ballClone.Parent = workspace  -- this places the clone ball into the workspace where it should be

	wait(3)
	ballClone:Destroy() -- I'd suggest using Debris Service in place of Destroy as it is more reliable

Ohhh that was the problem however now it gets cloned at th eright hans position and does not move forward in the way the hand is pointing at :confused:

1 Like