Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Script has no errors, and no signs of anything being wrong?

Asked by
obcdino 113
5 years ago

This script is supposed to shoot 2 balls simultaneously out of the boss' eyes. No error occurs, and when I view the explorer, no parts spawn in the eyes. I put in a print() at the end, and it printed every time. Any ideas as to why this isn't working?

(For reference, Chosen.Value is a random person's name)

01wait(2)
02while wait(5) do
03choice = 1 -- (choice is always 1 for testing purposes)
04-- // ATTACKS \\
05 
06if choice == 1 then
07    for i = 1,50 do
08    wait(0.2)
09    local ball = Instance.new("Part", script.Parent.Eye)
10    ball.Position = script.Parent.Eye.Position
11    ball.Shape = "Ball"
12    ball.BrickColor = BrickColor.Red()
13    ball.Transparency = 0.5
14    ball.Material = "Neon"
15    ball.CanCollide = false
View all 38 lines...
0
Id suggest starting with changing "neon" and "ball" to their Enum counterparts instead of Strings SerpentineKing 3885 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Using Instance.new() in this fashion is very tedious. I suggest making a pre-prepared ball for the boss to shoot out and put it into ServerStorage. Just make the ball to what you want it to look like and put in the essentials like rocket propulsion. When the boss shoots out the balls, say

01ball1 = game.ServerStorage.Ball:Clone()
02ball2 = game.ServerStorage.Ball:Clone()
03Par = script.Parent
04 
05ball1.Position = Par.Eye.Position
06ball2.Position =Par.Eye2.Position
07ball1.RocketPropulsion.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart
08ball2.RocketPropulsion.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart
09ball1.Parent = workspace
10ball2.Parent = workspace

Also, make sure that the Chosen.Value is the model of a player, with the body and such, and not the actual "Player" class. If it is the Player class, I can't help you any further, because I'm not a very advanced scripter myself. All I can say is use a model with the same name as the Chosen.Value, and make a new value that has the actual model as its value. I think "pairs" is the function...?

Ad
Log in to vote
0
Answered by 5 years ago

There are a few things I see wrong. Most importantly, you can't set MaxThrust to math.huge. That's going to fling your parts out of the world in one tick of the physics simulation, before you even get a chance to see them. They're gone before the simulation checks the part speed against the MaxSpeed; it's already too late for that property to have any effect.

Secondly, ball2 is not being set CanCollide=false, because you're missing a "2" on line 27

Lastly, because of how many parts you're spawning, this whole thing is going to have performance problems. The first comes from using Instance.new() with 2 arguments. There is a huge penalty for doing this when you're then immediately setting a bunch of properties (as you are), because of all the property change events. Instead, do Instance.new("Part"), set all your properties, set up the RocketPropulsion parented to the part, then set the part.Parent to Workspace as the very last step.

Consider using DebrisService to destroy the parts you spawn in a fixed amount of time, rather than hoping they don't have enough propulsion to never hit the kill plane. Otherwise, you may end up spawning too many parts. TBH, even this is kind of a sloppy fix; the proper way to do this is to spawn a fixed number of these projectile parts when the game starts or when the boss is about to spawn, to make a "pool" of them that you recycle (never allowing them to be destroyed, only put into storage someplace when not in use, anchored).

0
I'm not really looking for optimization, but I'll still take your other recommendations into account, thanks. obcdino 113 — 5y

Answer this question