Greetings DevForum,
I’m working on a simple punch system with three separate scripts
They are as follows:
--This is located in StarterPack
Player = game.Players.LocalPlayer
repeat wait() until Player.Character
Character = Player.Character
mouse = Player:GetMouse()
Enabled = true
mouse.Button1Down:Connect(function()
if Enabled == true then
script.Function:FireServer("Combat", Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2))
Enabled = false
wait(0.51)
Enabled =true
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(inputObject,gameProcessedEvent)
if gameProcessedEvent == true then return end
if inputObject.KeyCode == Enum.KeyCode.F and Enabled == true then
script.Function:FireServer("Combat", Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2))
Enabled = false
wait(0.51)
Enabled = true
end
end)
--This is located within a Remote event which is in the previous script
Enabled = true
Combo = 1
script.Parent.OnServerEvent:Connect(function(Player, Action, V1)
local c = Player.Character
if Enabled == false then return end
if Action == "Combat" then
Enabled = false
--Magnitude Combat (Creates a sphere of damage)
--for i,v in pairs(workspace:children()) do
--if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Humanoid") and v:FindFirstChild("Debounce") == nil and v~=c then
--if (v.HumanoidRootPart.Position-c.HumanoidRootPart.Position).magnitude < 5 then
-- v.Humanoid:TakeDamage(5)
--end
--end
--end
if Combo == 1 then
Combo = 2
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://9057077424"
local Anim = c.Humanoid:LoadAnimation(Track)
Anim:Play()
elseif Combo == 2 then
Combo = 1
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://90569327422"
local Anim = c.Humanoid:LoadAnimation(Track)
Anim:Play()
end
wait(0.2)
local Region = Region3.new(V1-Vector3.new(2,2,2),V1+Vector3.new(2,2,2))
local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
for i,v in pairs(RTable) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent:findFirstChild("Deb") == nil and v.Parent ~= c then
local Deb = Instance.new("BoolValue", v.Parent)
Deb.Name = "Deb"
game.Debris:AddItem(Deb,0.2)
v.Parent.Humanoid:TakeDamage(5)
local S = Instance.new("Sound", v)
S.SoundId = "rbxassetid://3932505023"
S.PlaybackSpeed = math.random(80,120)/100
S:Play()
local FX = Instance.new("Part", workspace.FX)
FX.Name = "CombatHit"
FX.CanCollide = false
FX.Anchored = true
FX.Material = "ForceField"
FX.Color = Color3.new(128,128,128)
FX.Size = Vector3.New(1,1,1)
local SM = Instance.new("SpecialMesh", FX)SM.MeshType = "Sphere"
SM.Scale = Vector3.new(0,0,0)
FX.CFrame = v.Parent.HumanoidRootPart.CFrame*CFrame.new(math.random(-20,20)/10,math.random(-20,20)/10,math.random(-20,20)/10)
end
end
wait(0.31)
Enabled = true
end
end)
--This is located in StarterGUI
workspace.FX.ChildAdded:connect(function(Child)
if Child.Name == "CombatHit" then
local Mesh = Child:WaitForChild("Mesh")
local Info = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0)
local Goals = {Scale=Vector3.new(5,5,5)}
local tween = game:GetService("TweenService"):Create(Child.Mesh,Info,Goals)
tween:Play()
local Info = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0)
local Goals = {Transparency = 1}
local tween = game:GetService("TweenService"):Create(Child,Info,Goals)
tween:Play()
end
end)```
When I run the game my stack ends at line 32 which is ```lua local Region = Region3.new(V1-Vector3.new(2,2,2),V1+Vector3.new(2,2,2))```. I can see the first punch come out but after that nothing happens.