Hi. I'm bigginer in coding and i like games who have magic skills, so i tried to make a map where is only pvp with magic skills. I tried to make this fireball and is ball "y" is not working
I want to appear "y" ball right where the "x" ball destroy.
Here's the code
local Player = game.Players.LocalPlayer local char = Player.Character or Player.CharacterAdded:Wait() local head = char:WaitForChild("Head") local shot = 1 local Mouse = Player:GetMouse() local x = Instance.new("Part") x.BrickColor = BrickColor.new("White") x.Shape = "Ball" x.Material = "Neon" x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Anchored = false x.CanCollide = false x.Transparency = 0 x.Size = Vector3.new(40,40,40); local y = Instance.new("Part") y.BrickColor = BrickColor.new("Black") y.Shape = "Ball" y.Material = "Neon" y.TopSurface = "Smooth" y.BottomSurface = "Smooth" y.Anchored = false y.CanCollide = false y.Transparency = 1 y.Size = Vector3.new(100, 100, 100); Mouse.Button1Down:connect(function() if shot == 1 then local cl = x:Clone() local v = Instance.new("BodyVelocity") v.MaxForce = Vector3.new(math.huge, math.huge, math.huge) v.Velocity = Player.Character.Torso.CFrame.lookVector * 110 v.Parent = cl cl.Parent = game.Workspace cl.CFrame = Player.Character.Torso.CFrame * CFrame.new(0,1,-5) shot = 0 wait(1) cl:Destroy() if cl:Destroy() then local cly = y:Clone() local b = Instance.new("BodyVelocity") b.MaxForce = Vector3.new(math.huge, math.huge, math.huge) b.Velocity = cl.CFrame.lookVector * 1 b.Parent = cly cly.Parent = game.Workspace cly.CFrame = cl.CFrame * CFrame.new(0,1,-5) wait(0.4) cly:Destroy() end game.Debris:AddItem(cl, 4) wait(0.6) shot = 1 end end)
The reason why ball 'y' won't appear is because :Destroy() does not return any boolean expression that would allow you to use it like you're currently attempting to use it in. In fact, it only returns 'void'. It's also worth mentioning that when you destroy an instance, all references linked to that instance are also voided and no longer useable.
To fix this, you have a decent amount of options to do. Probably the easiest for you and a 99% (if not 100%) guarantee to work is if you just check workspace to see if it's still there.
For this option, you need to change the ball's name so it'll search better. As I can probably assume you have a lot more parts in workspace named 'Part'
--This goes where you're setting up ball x's properties. At the bottom, we can put it. x.Name = "Ballx" --you can name it anything you wish, just make sure if you change the name so it will work with the FindFirstChild we will do.
I would also suggest changing 'ball y' to a similar name to remain consistent and if you ever need to do this in the future for ball y.
if workspace:FindFirstChild("Ballx") then --once again, make sure the name matches --do the stuff for y clone else print("This really shouldn't happen, unless you named it something else and forgot to change the name inside FindFirstChild)" end
Just replace that with the if statement you have and it should all work. Let me know if you have any questions regarding this.
As per request with the comment, this should destroy the ball aftertouch. Put this below the mouse button1down function
bally.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") --checking if its a player bally:Destroy() end end)
Change bally to whatever you set the name too. If you want ball x to be destroyed, just change the variable or add another function.