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)

wait(2)
while wait(5) do
choice = 1 -- (choice is always 1 for testing purposes)
-- // ATTACKS \\

if choice == 1 then
    for i = 1,50 do
    wait(0.2)
    local ball = Instance.new("Part", script.Parent.Eye)
    ball.Position = script.Parent.Eye.Position
    ball.Shape = "Ball"
    ball.BrickColor = BrickColor.Red()
    ball.Transparency = 0.5
    ball.Material = "Neon"
    ball.CanCollide = false
    ball.Size = Vector3.new(3.79, 3.79, 3.79)
    local RocketPropulsion = Instance.new("RocketPropulsion", ball)
    RocketPropulsion.MaxThrust = math.huge
    RocketPropulsion.MaxSpeed = 50
    RocketPropulsion.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart    
    local ball2 = Instance.new("Part", script.Parent.Eye2)
    ball2.Position = script.Parent.Eye2.Position
    ball2.Shape = "Ball"
    ball2.BrickColor = BrickColor.Red()
    ball2.Transparency = 0.5
    ball2.Material = "Neon" 
    ball.CanCollide = false
    ball2.Size = Vector3.new(3.79, 3.79, 3.79)
    local RocketPropulsion2 = Instance.new("RocketPropulsion", ball2)
    RocketPropulsion2.MaxThrust = math.huge
    RocketPropulsion2.MaxSpeed = 50
    RocketPropulsion2.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart
    RocketPropulsion:Fire()
    RocketPropulsion2:Fire()
    print('test')
    end
end -- 
end --
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

ball1 = game.ServerStorage.Ball:Clone()
ball2 = game.ServerStorage.Ball:Clone()
Par = script.Parent

ball1.Position = Par.Eye.Position
ball2.Position =Par.Eye2.Position
ball1.RocketPropulsion.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart
ball2.RocketPropulsion.Target = workspace[script.Parent.Chosen.Value].HumanoidRootPart
ball1.Parent = workspace
ball2.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