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)
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! :)