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

My script is creating a part and welding it, but my part's size increase from the center?

Asked by
Phyb 28
5 years ago
Edited 5 years ago

I have a LocalScript inside the player(s), which records if a player presses, and releases a certain key, which in this case, is Z. Pressing the key fires the GomuPistolEvent and KeyHeld = true, releasing the key fires the GomuPistolEvent and KeyHeld = false. I recently had a problem, which was quickly fixed, but now my issue lies from lines 89 to 104. During the while loop the part is increasing in size, so every tick it's size increases a weld is created to keep it welded to the player's arm. My problem is that the part is increasing in size from the center, making it appear that its going through the player's arm, and increasing in size away from the player's arm. After about 2 seconds the player frantically moving everywhere and dies. I want it to look like the part is expanding out of the player's arm, then when it is a certain size it contracts back to the player's arm. What would I do to fix this?

Code:

--//Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local ServerScriptService = game:GetService('ServerScriptService')
local Players = game:GetService('Players')
local GomuRemotes = ReplicatedStorage.Remotes.DevilFruits:WaitForChild('GomuGomu')

--//Variables
local GomuPistolEvent = GomuRemotes.GomuPistol:WaitForChild('GomuPistolEvent')
local DamageModule = require(ServerStorage.Server.DamageService)
local GomuAssets = ServerStorage.Assets.DevilFruits:WaitForChild('GomuGomu')

--//Animations
local GomuPistolAnim = Instance.new('Animation')
GomuPistolAnim.AnimationId = 'rbxassetid://2188557970'
GomuPistolAnimTrack = nil

--//Sounds
local GomuStretchSndFX = GomuAssets.SoundFX:WaitForChild('GomuStretch'):Clone()

--//Coding
--//Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local ServerScriptService = game:GetService('ServerScriptService')
local Players = game:GetService('Players')
local GomuRemotes = ReplicatedStorage.Remotes.DevilFruits:WaitForChild('GomuGomu')

--//Variables
local GomuPistolEvent = GomuRemotes.GomuPistol:WaitForChild('GomuPistolEvent')
local DamageModule = require(ServerStorage.Server.DamageService)
local GomuAssets = ServerStorage.Assets.DevilFruits:WaitForChild('GomuGomu')

--//Animations
local GomuPistolAnim = Instance.new('Animation')
GomuPistolAnim.AnimationId = 'rbxassetid://2188557970'
GomuPistolAnimTrack = nil

--//Sounds
local GomuStretchSndFX = GomuAssets.SoundFX:WaitForChild('GomuStretch'):Clone()

--//Coding
function Weld(Part0, Part1, C0,C1)
    local nWeld = Instance.new("Weld")
        nWeld.Parent = Part0
        nWeld.Part0 = Part0
        nWeld.Part1 = Part1
        nWeld.C0 = C0 or CFrame.new(0, 0, 0)
        nWeld.C1 = C1 or CFrame.new(0, 0, 0)
    return nWeld    
end

function GomuGomuPistol(PlayerWhoSent, KeyHeld, MousePosition)
    local Character = PlayerWhoSent.Character
    local Humanoid = Character:FindFirstChildOfClass('Humanoid')
    local RightArm = Character:WaitForChild('RightLowerArm')
    local RightHand = Character:WaitForChild('RightHand')
    local LeftArm = Character:WaitForChild('LeftLowerArm')
    local LeftHand = Character:WaitForChild('LeftHand')
    local Damaging = false
    local Attacking = false
    local Damage = 25
    local Range = 25
    local BodyGyro = Instance.new('BodyGyro')
    local BodyPosition = Instance.new('BodyPosition')
    local ArmStretch = Instance.new('Part') 

    if KeyHeld then
        GomuPistolAnimTrack = Humanoid:LoadAnimation(GomuPistolAnim)
        GomuPistolAnimTrack:Play()
        GomuPistolAnimTrack.KeyframeReached:Connect(function(Keyframe)
            if Keyframe == 'Charge' and KeyHeld then
                GomuPistolAnimTrack:AdjustSpeed(0)
                print('pistolcharge')
                Attacking = true
            end
        end)
    elseif not KeyHeld then
        BodyGyro.Name = 'SkillGyro'
        BodyGyro.D = 100
        BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
        BodyGyro.CFrame = CFrame.new(Character.LowerTorso.Position, MousePosition)
        BodyPosition.Name = 'SkillPosition'
        BodyPosition.Position = Character.HumanoidRootPart.Position
        BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        BodyGyro.Parent = Character.LowerTorso
        BodyPosition.Parent = Character.LowerTorso
        GomuPistolAnimTrack:AdjustSpeed(1)
        GomuPistolAnimTrack.KeyframeReached:Connect(function(Keyframe)
            if Keyframe == 'Pistol' then
                GomuPistolAnimTrack:AdjustSpeed(0)
                print('pistol')
                Damaging = true
                ArmStretch.Name = 'ArmStretchRight'
                ArmStretch.Size = RightArm.Size
                ArmStretch.Position = RightArm.Position
                ArmStretch.Anchored = false
                ArmStretch.TopSurface = 0
                ArmStretch.BottomSurface = 0
                ArmStretch.CanCollide = false
                ArmStretch.Parent = Character
                Weld(ArmStretch, RightArm, CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0))
                RightArm.Transparency = 1
                RightHand.Transparency = 1
                GomuStretchSndFX.Playing = true
                GomuStretchSndFX.Parent = RightArm
                while Keyframe == 'Pistol' do
                    ArmStretch.Size = ArmStretch.Size + Vector3.new(0, 1, 0)
                    ArmStretch.CFrame = ArmStretch.CFrame * CFrame.new(Vector3.new(0, 0.5, 0))
                    ArmStretch.Position = ArmStretch.Position * Vector3.new(0, 0.5, 0)
                    Weld(ArmStretch, RightArm, CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0))
                    if ArmStretch.Size.Y == Range then
                        ArmStretch.Size = ArmStretch.Size + Vector3.new(0, 1, 0)
                        Weld(ArmStretch, RightArm, CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0))
                        if ArmStretch.Size == RightArm.Size then
                            break
                        end
                    end
                    wait()
                end
            end
            GomuPistolAnimTrack:AdjustSpeed(1)
            Character.LowerTorso:WaitForChild('SkillGyro'):Destroy()
            Character.LowerTorso:WaitForChild('SkillPosition'):Destroy()
            Character:WaitForChild('ArmStretchRight'):Destroy()
            RightArm:WaitForChild('GomuStretch'):Destroy()
            if RightArm.Transparency == 1 then RightArm.Transparency = 0 end
            if RightHand.Transparency == 1 then RightHand.Transparency = 0 end
            Attacking = false
        end)
    end

    RightArm.Touched:Connect(function(hitPart)
        if Attacking and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
            Damaging = false
            local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
            DamageModule.Combat(HumanoidToDamage, Damage)
        end
    end)
    LeftArm.Touched:Connect(function(hitPart)
        if Attacking and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
            Damaging = false
            local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
            DamageModule.Combat(HumanoidToDamage, Damage)
        end
    end)
end

GomuPistolEvent.OnServerEvent:Connect(GomuGomuPistol)
0
You cannot get the Mouse from the server, and why do you have your events all nested in the OnServerEvent? You're creating tons of connections for nothing. User#19524 175 — 5y
0
True, I should have the events on a function instead of OnServerEvent, but I'm not getting the mouse from the server, it's getting it from the playerwhosent. That's why the Mouse and MousePosition argument on in the parameters in OnServerEvent, and when I fire it from the localscript. Phyb 28 — 5y
0
The mouse isn't even the problem, its resizing the ArmStretch part. Phyb 28 — 5y
0
If you're not getting the mouse from the server, please explain line 64. User#19524 175 — 5y
View all comments (6 more)
0
Line 64 is getting the position of the mouse through the Mouse parameter in the function arguments. I don't see any problem with it, since it works as I intend it to. Phyb 28 — 5y
0
Do not pass the mouse as a parameter, use the MousePosition instead. User#19524 175 — 5y
0
if I only pass the MousePisiton as a parameter, I have to remove line 64, and if I do that, the player can no longer aim while they hold down their key Phyb 28 — 5y
0
and if I try replacing line 64, with MousePosition = MousePosition, it still has the same result as my previous comment. Phyb 28 — 5y
0
Oh, I see now that during testing client and server are one in the same, since when I tested it in a normal game the player can't aim when they press the Z key. I'm perplexed on how to fix it still. Phyb 28 — 5y
0
I've changed the code, and edited it in the question, a lot to adjust for not being able to use the Mouse parameter in the while loop I had. Phyb 28 — 5y

1 answer

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

If you want to resize a part from in one direction and not from both, you would have to change the size of the part and move the part at the same time.

If you resize the part by 1, you would have to move the part by half of that so one of the edges stays where it was.

Since you are increasing ArmStretch.Size.Y by Vector3.new(0, 1, 0), you would have to change the position by Vector3.new(0, 0.5, 0).

I hope this helps! :)

0
Thank you for the feedback, but part is still resizing in both directions, and it's above the player's arm. I tried changing the Vector3.new() arguments in the other 2 places, but it they both have the same kind of result. Phyb 28 — 5y
0
What you are saying is that not only do I have to do is ArmStretch.Size = ArmStretch.Size + Vector3.new(0, 1, 0), I need to add ArmStretch.Position = ArmStretch.Position + Vector3.new(0, 0.5, 0), right? Phyb 28 — 5y
0
Changing the position like that will only work if the orientation is 0. You need to adjust it to fit the orientation. chomboghai 2044 — 5y
0
You can multiply ArmStretch.CFrame * CFrame.new(Vector3.new(0, 0.5, 0)) to automatically incorporate orientation. chomboghai 2044 — 5y
View all comments (5 more)
0
Mmm ok. What line would I put that in? Phyb 28 — 5y
0
Sorry to be such a bother haha, I'm kind of new to Lua, but not to programming. Some things kind of don't make sense to me at first. Phyb 28 — 5y
0
You would put that after you change the size. chomboghai 2044 — 5y
0
Alright, I changed a lot of code around since I realized that i can't call mouse.hit.p in a while loop. I now have ANOTHER problem, and I can't test to see if the changes you told me work properly, but just to confirm; I edited the code in the question. It should be from lines 73 to 98. Phyb 28 — 5y
0
Nevermind about the errors, I changed the code above since I've made a lot of changes. The code I changed according to what you have told me is from lines 73 to 99. The part still increases in both directions. Phyb 28 — 5y
Ad

Answer this question