Missile Coding Issue

Hello there. I’ve got a slight issue I’m trying to fix.

Pictures underneath. (As I’m a new member, I can’t upload more quality pictures)

Screen;
https://gyazo.com/ad7ac752dfd9d7d86448fe96a194802f

Explorer;
https://gyazo.com/bdde224c90b82fbaaf18b2572e887927

StarterGUI;
https://gyazo.com/c6b8dbccaaf1ea5df6cf0b49abd2e8f2

Script;
https://gyazo.com/5fb0a3aef2ae847e0f6653da1cf9beb3

What I want it to do is;

  1. Player types in coordinates (x,y,z)
  2. Player clicks the part named “ClickPart”
  3. Missile Part launches 100 studs into the air, then proceeds towards the coordinates.

(I’m not doing pathfinding yet, so it is fine if it goes right towards it, with no regard to other parts in the way. Just getting the basis done first.)

Now what it actually does;
https://gyazo.com/050a6d7808c0c52f7850f869183fb98b

All goes fine, it goes up to 100 studs, then just deviates from the gameplan and does its own thing. I don’t even know why it would go up and down for the second time. Just makes no sense.

That is my issue. This is my first post, so please be lenient if I didn’t follow the format correctly. This is my first time attempting to use Tweening. If there is another more efficient way, please do feel free to explain.

(I’m trying to make an ICBM Launcher)

Thanks for all the help, and all feedback, whether or not it is related to the problem, is appreciated.

EDIT: If access or more pictures is needed, I’ll provide.

Here’s the modified code, just to avoid viewing the picture:

local plr = game.Players.LocalPlayer
local tweenService = game:GetService("TweenService")
local frame = game:GetService("StarterGui").missile.Frame
local x1, y1, z1 = frame.x.Text, frame.y.Text, frame.z.Text
local missile = workspace:FindFirstChild("missile")
local x, y, z = missile.Position.X, missile.Position.Y, missile.Position.Z

local function onMouseClick(player)
    local startup = Vector3.new(x, 100, z)
    local destination = Vector3.new(x1, y1, z1)

    local startupTween = tweenService:Create(missile, TweenInfo.new(2), {Position = startup})
    local destinationTween = tweenService:Create(missile, TweenInfo.new(2), {Position = destination})

    startupTween:Play(); startupTween.Completed:Wait()
    destinationTween:Play()
end

script.Parent.MouseClick:Connect(onMouseClick)

Analysis show that you are reading values from the StarterGui, which are default GUI for players. They are not updated by the player. Please direct into player.PlayerGui instead.

Player input do not replicate to server, so server always read the same input regardless what the player types in. To fix this, you will need to play around with RemoteEvents firing from the client. Not secure through this way, but it’s the best of what I can think of at this time of writing.

LocalPlayer is nil on server. The usage of LocalPlayer is only through LocalScript.

Pathfinding is unnecessary, only needed for humanoids.

Lack of debounce creates the “double bounce” effect. Consider adding debounce to prevent several clicks at once on the object. Also if you plan on multiple missiles, consider saving the part in ServerStorage and using missile:Clone() to create a duplicate instance of it then parent the clone to the workspace and run the tweens on it.

To explain what I mean by PlayerGui. Everything from StarterGui is cloned to a player when they join. When this happens, these cloned GUI are parented to the player’s PlayerGui.


I’ll write a fixed version of the script soon as I’m on vacation and unable to work on my primary projects.

The code is sent in PM.

3 Likes

Alright, I will play around and see what happens. Would it be possible to make a confirmation button, that when pressed, inserts the coordinates into an IntValue object, which I can then use? Thanks for the reply and I’ll be more than happy to see your version of it.

Thanks! I’ll go play around and see what I can do.