yeah the title pretty much explains my problem
my function returns nil before even finishing, the rest of the script works fine
module.rollDice = function(dice)
local faces={
["Back"]=5,
["Bottom"]=6,
["Front"]=2,
["Left"]=4,
["Right"]=3,
["Top"]=1
}
local function getsurface(surfacenormal)
local normal = dice.PrimaryPart.CFrame:VectorToObjectSpace(surfacenormal)
local nx,ny,nz = math.round(normal.X),math.round(normal.Y),math.round(normal.Z)
if nx ~= 0 and (ny == 0 and nz == 0) then
if nx > 0 then
return("Front")
else
return("Back")
end
elseif ny ~= 0 and (nx == 0 and nz == 0) then
if ny > 0 then
return("Top")
else
return("Bottom")
end
elseif nz ~= 0 and (nx == 0 and ny == 0) then
if nz > 0 then
return("Left")
else
return("Right")
end
end
end
local Tween1 = TS:Create(dice.PrimaryPart,TweenInfo.new(0.1,Enum.EasingStyle.Linear),{["CFrame"]=CFrame.new(dice.PrimaryPart.Position)*CFrame.Angles(math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)))})
Tween1:Play()
Tween1.Completed:Connect(function()
local Tween2 = TS:Create(dice.PrimaryPart,TweenInfo.new(0.1,Enum.EasingStyle.Linear),{["CFrame"]=CFrame.new(dice.PrimaryPart.Position)*CFrame.Angles(math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)))})
Tween2:Play()
Tween2.Completed:Connect(function()
local Tween3 = TS:Create(dice.PrimaryPart,TweenInfo.new(0.1,Enum.EasingStyle.Back),{["CFrame"]=CFrame.new(dice.PrimaryPart.Position)*CFrame.Angles(math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)),math.rad(90*math.random(1,4)))})
Tween3:Play()
Tween3.Completed:Connect(function()
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {dice.PrimaryPart}
local origin = dice.PrimaryPart.Position+Vector3.new(0,dice.PrimaryPart.Size.Y,0)
local results = workspace:Raycast(origin,dice.PrimaryPart.Position-origin,params)
local surface = getsurface(results.Normal)
print(faces[surface]) -- line 52
return faces[surface]
end)
end)
end)
end
local num = module.rollDice(map.Dice) -- line 101
print(num)