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

I'm stuck halfway through a script, How can I make a script that moves a part?

Asked by 5 years ago

I have planned to make something, a GUI that once clicked, shoots something. The only thing I want to make right now is a simple textbutton that says "click to shoot a ball", after that, It shoots a ball forward, and that's it.

This is the script.

LocalScript In StarterGui > ScreenGui > Textbutton

user = script.Parent.Parent.Parent

script.Parent.TextButton.MouseButton1Click:connect(function()
    game.ReplicatedStorage.Events.TEST_SummonBal:FireServer(user)
    print("oh nice you shot a ball") --Just to make sure the FireServer worked.
end)

Script in ServerScriptService

game.ReplicatedStorage.Events.TEST_SummonBal.OnServerEvent:Connect(function(user)
    local player = user.Character
    local Root = player:FindFirstChild("HumanoidRootPart")
    local Bullet = game.ReplicatedStorage.Weapons.BasicBullet:Clone()
    local MoveScript = game.ServerStorage.MoveScript:clone() --Movescript is Disabled, by the way.

    Bullet.Parent = game.Workspace
    MoveScript.Parent = Bullet --To make the Moving Part Script happen.

    Bullet.Position = Root.Position

    MoveScript.Disabled = false

    wait(3)

    Bullet:Destroy()

end)

--Sidenote: "Bullet" can't collide with the player.

It all seems to work, but one thing. I don't know how to make the "MoveScript", Which must, err...

You guys remember pokemon advanced?, The attacks worked in a way that they moved forward from the player, Here's a video example of that https://youtu.be/kefQj5vew6o?t=218 (Notice Persian's PayDay attack)

That's what I want the movescript to do, However, I don't know how to make it.

You can give me a hand, right?

If you're going to be those persons and right out just post the script, AT LEAST Explain me how it works, I won't learn anything if you don't teach me.

0
Firstly, you don't need to put 'user' in the FireServer() parameter in the local script. OnServerEvent automatically gets the player that fired the event. Secondly, :connect is deprecated, you should use :Connect instead. Lastly, you should try to code the script yourself and post your attempt if you fail. LawlR 182 — 5y
0
About the third one: I Don't know how, I don't know how to make ANYTHING of the script, detecting the player's "front", disabling gravity, making it move forward, nothing, That's why I asked for help. Chris75764 49 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Hey Chris75764,

Solution:

Try using the lookVector property of the CFrame and use a BodyVelocity object to make the object move forward. I wrote my own piece of code to make just a simple ball move forward after it spawns in front of the character. Here it is:

Example Code

-- Local Script under StarterGui
local uis = game:GetService("UserInputService") -- The UserInputService to detect input.
local players = game:GetService("Players") -- Players service
local player = players.LocalPlayer -- The player that the script is under.

uis.InputBegan:Connect(function(obj, gp) -- Anonymous function with the input and gameProcessed event as arguments.
    if obj.KeyCode == Enum.KeyCode.Q and not gp then -- Checks if the player pressed 'Q' and if it was pressed while typing in chat or meant to be pressed.
        local part = Instance.new("Part") -- Makes a part
        -- Property preferences --
        part.BrickColor = BrickColor.Random()
        part.Transparency = math.random()
        part.Size = Vector3.new(5, 5, 5)
        part.Shape = Enum.PartType.Ball
        -- Property preferences --

        local char = player.Character -- The character of the player
        local root = char:WaitForChild("HumanoidRootPart") -- The HumanoidRootPart of the player
        part.CFrame = root.CFrame * CFrame.new(0, 0, -3) -- Spawns the part 3 studs in front of the character's humanoid.
        local bv = Instance.new("BodyVelocity") -- Makes the body velocity object.
        bv.Parent = part -- Parents it to the part
        bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- Sets its maxForce to infinity
        bv.Velocity = root.CFrame.lookVector * 100 -- Makes it move forward at a speed of 100.
        part.Parent = workspace -- Parents the part to workspace.
    end
end)

Here is a video reference you can use:

How to make a fireball

Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

KingLoneCat

0
Wow, You're such a gentleman when talking, You know?, Anyways, Thanks, Not quite what I asked, But I can shape it up to become the script I want, Don't worry!, You did a awesome job. Chris75764 49 — 5y
0
Thanks for the compliment, and it's a pleasure to be of help. KingLoneCat 2642 — 5y
Ad

Answer this question