so im making a turn based game and apparently the script just wait forever becouse the module return nil, but in the image below you can see it return true, the point in the end is that it try to get the value before the script finish
if AttackFirst == Character then
ChatService:Chat(Character,PlayerMove.Name,2)
local fin = false
local fin2 = false
fin = AttackModule[PlayerMove.Name](Character,Npc)
print(fin)
repeat wait() until fin == true
print("Fire2")
fin2 = AttackModule[PlayerMove.Name](Npc,Character)
repeat wait() until fin2 == true
AttackEvent:FireClient(player)
end
Module:
local ServerStore = game:GetService("ServerStorage")
local Animations = ServerStore:WaitForChild("Animations")
local Attacks = {
["Punch"] = function(Character,Enemy)
local Humanoid = Character.Humanoid
local EnemyHumanoid = Enemy.Humanoid
local StartCharCFrame = Character.Torso.CFrame
local StartCharPosition = Character.Torso.Position
local StartEnemyCFrame = Enemy.Torso.CFrame
local StartEnemyPosition = Enemy.Torso.Position
local Animation = Animations.Fists.Punch
local Track = Humanoid:LoadAnimation(Animation)
if Character.HumanoidRootPart.Anchored == true then Character.HumanoidRootPart.Anchored = false end
if Enemy.HumanoidRootPart.Anchored == true then Enemy.HumanoidRootPart.Anchored = false end
Humanoid:MoveTo(Enemy.Torso.Position + Vector3.new(0,0,-2))
local targetReached = false
local connection
connection = Humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
Track:Play()
Track.Stopped:wait()
wait(0.1)
EnemyHumanoid:TakeDamage(4)
Character.Torso.CFrame = StartCharCFrame
Enemy.Torso.CFrame = StartEnemyCFrame
wait(0.5)
if Character.HumanoidRootPart.Anchored == false then Character.HumanoidRootPart.Anchored = true end
if Enemy.HumanoidRootPart.Anchored == false then Enemy.HumanoidRootPart.Anchored = true end
print("Returned")
return true
end)
end,
}
return Attacks
here you are returning from the callback, don’t do that.
Try instead
local returnValue
connection = Humanoid.MoveToFinished:Connect(function(reached)
... - Other stuff you have here
returnValue = true
end)
return returnValue
it return nil
and the code only do the first punch then stop again
well instead of trying to fix this you got any other way to make the server script wait for the module function to finish?
Are you wanting to wait to return until MoveToFinished?
local ServerStore = game:GetService("ServerStorage")
local Animations = ServerStore:WaitForChild("Animations")
local Attacks = {
["Punch"] = function(Character,Enemy)
local Humanoid = Character.Humanoid
local EnemyHumanoid = Enemy.Humanoid
local StartCharCFrame = Character.Torso.CFrame
local StartCharPosition = Character.Torso.Position
local StartEnemyCFrame = Enemy.Torso.CFrame
local StartEnemyPosition = Enemy.Torso.Position
local Animation = Animations.Fists.Punch
local Track = Humanoid:LoadAnimation(Animation)
if Character.HumanoidRootPart.Anchored == true then Character.HumanoidRootPart.Anchored = false end
if Enemy.HumanoidRootPart.Anchored == true then Enemy.HumanoidRootPart.Anchored = false end
Humanoid:MoveTo(Enemy.Torso.Position + Vector3.new(0,0,-2))
local targetReached = false
Humanoid.MoveToFinished:Wait()
targetReached = true
connection:Disconnect()
connection = nil
Track:Play()
Track.Stopped:wait()
wait(0.1)
EnemyHumanoid:TakeDamage(4)
Character.Torso.CFrame = StartCharCFrame
Enemy.Torso.CFrame = StartEnemyCFrame
wait(0.5)
if Character.HumanoidRootPart.Anchored == false then Character.HumanoidRootPart.Anchored = true end
if Enemy.HumanoidRootPart.Anchored == false then Enemy.HumanoidRootPart.Anchored = true end
print("Returned")
return true
end,
}