I have a script with functions, but for some reason it’s not working also I added prints and it doesn’t print…any idea how to fix this?
Here’s a part of the Script:
local Damage = 25
local DamageStopper = false
Event.OnServerEvent:Connect(function(Player)
print("Event")--prints
local Animations = {
RightPunch = script.Parent.Animations:WaitForChild("RightPunch"),
LeftPunch = script.Parent.Animations:WaitForChild("LeftPunch"),
RightKick = script.Parent.Animations:WaitForChild("RightKick")
}
local function RightTouched()
print("function0")--Does not print and everything under too
script.Parent.Parent.RightHand.Touched:Connect(function(hit)
print("function1")
if DamageStopper == false and hit then
print("function2")
local TargetHumanoid = hit.Parent:FindFirstChild("Humanoid")
if script.Parent.Parent.Name == hit.Parent.Name then return end
print("function3")
TargetHumanoid:TakeDamage(Damage)
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Name = "Knockback"
KnockBack.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
KnockBack.Velocity = (-hit.Parent.HumanoidRootPart.CFrame.lookVector) * 100
KnockBack.Parent = hit.Parent.HumanoidRootPart
local Debreis = game:GetService("Debris")
Debreis:AddItem(KnockBack,0.001)
DamageStopper = true
wait(Cooldown)
DamageStopper = false
print("function4")
end
end)
end
Call the function like this
RightTouched()
You never exactly connected/called the function anywhere in your script…?
Here’s one of the functions that is used:
if CombatCount == 1 and CanAttack == true then
print("1")
RightTouched()
local RightPunch = Player.Character.Humanoid:LoadAnimation(Animations.RightPunch)
RightPunch:Play()
CombatCount = 2
CanAttack = false
wait(Cooldown)
CanAttack = true
Can you pretty please send us the whole script?
Add another print statement after you call the function?
if CombatCount == 1 and CanAttack == true then
print("1")
RightTouched()
local RightPunch = Player.Character.Humanoid:LoadAnimation(Animations.RightPunch)
RightPunch:Play()
print("2")
CombatCount = 2
CanAttack = false
wait(Cooldown)
CanAttack = true
Does not print 1 or 2 for some reason.
local Event = script.Parent:WaitForChild("RemoteEvent")
local CombatCount = 1
local CanAttack = true
local Cooldown = 0.25
local Damage = 25
local DamageStopper = false
Event.OnServerEvent:Connect(function(Player)
print("Event")
local Animations = {
RightPunch = script.Parent.Animations:WaitForChild("RightPunch"),
LeftPunch = script.Parent.Animations:WaitForChild("LeftPunch"),
RightKick = script.Parent.Animations:WaitForChild("RightKick")
}
local function RightTouched()
print("function0")
script.Parent.Parent.RightHand.Touched:Connect(function(hit)
print("function1")
if DamageStopper == false and hit then
print("function2")
local TargetHumanoid = hit.Parent:FindFirstChild("Humanoid")
if script.Parent.Parent.Name == hit.Parent.Name then return end
print("function3")
TargetHumanoid:TakeDamage(Damage)
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Name = "Knockback"
KnockBack.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
KnockBack.Velocity = (-hit.Parent.HumanoidRootPart.CFrame.lookVector) * 100
KnockBack.Parent = hit.Parent.HumanoidRootPart
local Debreis = game:GetService("Debris")
Debreis:AddItem(KnockBack,0.001)
DamageStopper = true
wait(Cooldown)
DamageStopper = false
print("function4")
end
end)
end
local function LeftTouched()
script.Parent.Parent.LeftHand.Touched:Connect(function(hit)
if DamageStopper == false and hit then
local TargetHumanoid = hit.Parent:FindFirstChild("Humanoid")
if script.Parent.Parent.Name == hit.Parent.Name then return end
TargetHumanoid:TakeDamage(Damage)
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Name = "Knockback"
KnockBack.MaxForce = Vector3.new(100000,100000,100000)
KnockBack.Velocity = (-hit.Parent.HumanoidRootPart.CFrame.lookVector) * 100
KnockBack.Parent = hit.Parent.HumanoidRootPart
local Debreis = game:GetService("Debris")
Debreis:AddItem(KnockBack,0.001)
DamageStopper = true
wait(Cooldown)
DamageStopper = false
end
end)
end
local function FootTouched()
script.Parent.Parent.RightFoot.Touched:Connect(function(hit)
if DamageStopper == false and hit then
local TargetHumanoid = hit.Parent:FindFirstChild("Humanoid")
if script.Parent.Parent.Name == hit.Parent.Name then return end
TargetHumanoid:TakeDamage(Damage)
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Name = "Knockback"
KnockBack.MaxForce = Vector3.new(100000,100000,100000)
KnockBack.Velocity = (-hit.Parent.HumanoidRootPart.CFrame.lookVector) * 100
KnockBack.Parent = hit.Parent.HumanoidRootPart
local Debreis = game:GetService("Debris")
Debreis:AddItem(KnockBack,0.001)
DamageStopper = true
wait(Cooldown)
DamageStopper = false
end
end)
end
print("Done")
if CombatCount == 1 and CanAttack == true then
print("1")
RightTouched()
print("2")
local RightPunch = Player.Character.Humanoid:LoadAnimation(Animations.RightPunch)
RightPunch:Play()
CombatCount = 2
CanAttack = false
wait(Cooldown)
CanAttack = true
elseif CombatCount == 1 and CanAttack == false then
print("2")
LeftTouched()
local RightPunch = Player.Character.Humanoid:LoadAnimation(Animations.LeftPunch)
RightPunch:Play()
CombatCount = 1
CanAttack = false
wait(Cooldown)
CanAttack = true
end
end)
Those prints are not inside of the function, are you sure the conditions of CombatCount and CanAttack are met?
My script is up above so you can see the prints and etc.
Alright so upon the event being fired, which prints happen? Which ones don’t that you want to?
So like the only print that prints is Event at the top.
When the event gets called, its missing the end statement. You also have to call the function by doing RightTouched(). Here is the improved Script because its hard to explain: (I dont know why code block dosent work
)
local Damage = 25
local DamageStopper = false
local coolDown = 5
local Event = game.ReplicatedStorage.RemoteEvent – replace this with the name
local function RightTouched() – this can be outside of the remote event function
print(“function0”)–Does not print and everything under too
script.Parent.Parent.RightHand.Touched:Connect(function(hit)
print(“function1”)
if DamageStopper == false and hit then
print(“function2”)
local TargetHumanoid = hit.Parent:FindFirstChild(“Humanoid”)
if script.Parent.Parent.Name == hit.Parent.Name then return end
print(“function3”)
TargetHumanoid:TakeDamage(Damage)
local KnockBack = Instance.new(“BodyVelocity”)
KnockBack.Name = “Knockback”
KnockBack.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
KnockBack.Velocity = (-hit.Parent.HumanoidRootPart.CFrame.lookVector) * 100
KnockBack.Parent = hit.Parent.HumanoidRootPart
local Debreis = game:GetService(“Debris”)
Debreis:AddItem(KnockBack,0.001)
DamageStopper = true
wait(coolDown)
DamageStopper = false
print(“function4”)
end
end)
end
Event.OnServerEvent:Connect(function(Player)
print(“Event”)–prints
local Animations = {
RightPunch = script.Parent.Animations:WaitForChild(“RightPunch”),
LeftPunch = script.Parent.Animations:WaitForChild(“LeftPunch”),
RightKick = script.Parent.Animations:WaitForChild(“RightKick”)
}
RightTouched() --runs the function you wrote above
end)
Ummmm where? Is the script exactly?
I don’t know, it might have to do with the WaitForChilds in the animations table if it doesn’t even print “Done” near the bottom. Check to see if there is just a single “Infinite yield possible” in the console.
if that dosent work, idk what will.
It doesn’t work
thanks for trying though.
1 Like
Always, I hope u find the solution!
YES I FOUND THE SOLUTION! Thank you everyone who helped!!! 