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 69 to 94. I run tests to check if the part "ArmStretch" is being created, which in fact it is, and since it is unanchored it falls to the ground through the map. The "Weld" isn't being created for some reason, and I'm not getting any error messages. I have also tried rewriting the code to create weld to "Weld = Instance.new('ManualWeld')" but that doesn't seem to work either. What am I doing wrong?
Big Thanks!
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) --//Animations local GomuPistolAnim = Instance.new('Animation') GomuPistolAnim.AnimationId = 'rbxassetid://2188557970' GomuPistolAnimTrack = nil --//Coding GomuPistolEvent.OnServerEvent:Connect(function(PlayerWhoSent, KeyHeld, Mouse, MousePosition) local Character = game.Workspace:WaitForChild(PlayerWhoSent.Name) 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 = nil local Cooldown = nil local Range = nil local BodyGyro = Instance.new('BodyGyro') local BodyPosition = Instance.new('BodyPosition') local ArmStretch = nil local Weld = nil if KeyHeld then BodyGyro.Parent = Character.LowerTorso BodyGyro.Name = 'SkillGyro' BodyGyro.D = 100 BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge) BodyPosition.Parent = Character.LowerTorso BodyPosition.Name = 'SkillPosition' BodyPosition.Position = Character.HumanoidRootPart.Position BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge) GomuPistolAnimTrack = Humanoid:LoadAnimation(GomuPistolAnim) GomuPistolAnimTrack:Play() GomuPistolAnimTrack.KeyframeReached:Connect(function(Keyframe) if KeyHeld and Keyframe == 'Charge' then GomuPistolAnimTrack:AdjustSpeed(0) end end) print('pistolcharge') Attacking = true while KeyHeld do MousePosition = Mouse.Hit.p BodyGyro.CFrame = CFrame.new(Character.LowerTorso.Position, MousePosition) wait() if not KeyHeld then break end end else GomuPistolAnimTrack:AdjustSpeed(1) print('pistol') BodyGyro.CFrame = CFrame.new(Character.LowerTorso.Position, MousePosition) GomuPistolAnimTrack.KeyframeReached:Connect(function(Keyframe) if Keyframe == 'Pistol' then GomuPistolAnimTrack:AdjustSpeed(0) Damaging = true Damage = 25 ArmStretch = Instance.new('Part') ArmStretch.Parent = Character ArmStretch.Name = 'ArmStretchRight' ArmStretch.Color = RightArm.Color ArmStretch.Size = RightArm.Size ArmStretch.Anchored = false ArmStretch.TopSurface = 0 ArmStretch.BottomSurface = 0 ArmStretch.CanCollide = false RightArm.Transparency = 1 RightHand.Transparency = 1 Weld = Instance.new('Weld') Weld.Parent = ArmStretch Weld.Part0 = ArmStretch Weld.Part1 = RightArm Weld.C0 = CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0) while Keyframe == 'Pistol' do ArmStretch.Size = ArmStretch.Size+Vector3.new(0, 0.1, 0) if ArmStretch.Size.Y == Range then ArmStretch.Size = ArmStretch.Size-Vector3.new(0, 0.1, 0) if ArmStretch.Size.Y == 1 then break end end wait() end GomuPistolAnimTrack:AdjustSpeed(1) Character.LowerTorso:WaitForChild('SkillGyro'):Destroy() Character.LowerTorso:WaitForChild('SkillPosition'):Destroy() Character:WaitForChild('ArmStretchRight'):Destroy() if RightArm.Transparency == 1 then RightArm.Transparency = 0 end if RightHand.Transparency == 1 then RightHand.Transparency = 0 end Attacking = false end 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)
i think i've got a decent answer-- though, don't quote me, since i may be wrong.
don't set the parent for ArmStretch until after you set every other property. including welds. because, from what i've heard and read about, parenting can cause performance issues if it's the first thing done. i may be wrong on that, though.
so, what i would do, is simply set the parent last for ArmStretch, and just to make sure the weld is existant, set the parent of the weld TO ArmStretch right before ArmStretch is put in the character, such like this:
ArmStretch = Instance.new('Part') ArmStretch.Name = 'ArmStretchRight' ArmStretch.Color = RightArm.Color ArmStretch.Size = RightArm.Size ArmStretch.Anchored = false ArmStretch.TopSurface = 0 ArmStretch.BottomSurface = 0 ArmStretch.CanCollide = false RightArm.Transparency = 1 RightHand.Transparency = 1 Weld = Instance.new('Weld') Weld.Part0 = ArmStretch Weld.Part1 = RightArm Weld.C0 = CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0) --this is what i mean vvvv Weld.Parent = ArmStretch ArmStretch.Parent = Character
hope i helped in some way!