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)
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
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:
Clone ball
Create velocity, parent to clone ball
Parent clone ball to workspace
Debris clone ball after x seconds or on hit event.
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