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)

10 comments
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.
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.
The mouse isn't even the problem, its resizing the ArmStretch part.
If you're not getting the mouse from the server, please explain line 64.
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.
Do not pass the mouse as a parameter, use the MousePosition instead.
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
and if I try replacing line 64, with MousePosition = MousePosition, it still has the same result as my previous comment.
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.
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.