Hello, guys. I have create a script, but is don’t fonction. It’s for a die. Can you help me?
local die = script.Parent
local rnd = Random.new(tick())
local upPart = workspace.UpPart
local function isSide(facing, p2pVec)
local angle = math.acos(facing:Dot(p2pVec))
local deg = angle * 180/math.pi
if deg < 45 then
return true
end
end
local function isLooking(obj1, obj2)
local p2pVec = (obj2.Position - obj1.Position).unit
– check for 2
local found = isSide(obj1.CFrame.LookVector, p2pVec)
if found then
return 2
end
– check for 5
local found = isSide(-obj1.CFrame.LookVector, p2pVec)
if found then
return 5
end
– check for 3
local found = isSide(obj1.CFrame.RightVector, p2pVec)
if found then
return 3
end
– check for 4
local found = isSide(-obj1.CFrame.RightVector, p2pVec)
if found then
return 4
end
– check for 6
local found = isSide(obj1.CFrame.UpVector, p2pVec)
if found then
return 6
end
– check for 1
local found = isSide(-obj1.CFrame.UpVector, p2pVec)
if found then
return 1
end
end
local function rollDie()
die.Anchored = false
local x = rnd:NextInteger(-30, 30)
local x = rnd:NextInteger(-30, 30)
local x = rnd:NextInteger(-30, 30)
die.RotVelocity = Vector3.new(x, y, z)
wait(3)
local result = isLooking(die, upPart)
print ("Result = ", result)
wait(3)
die.Anchored = true
die.Position = Vector3.new(0, 30, 0)
end
local die = script.Parent
local rnd = Random.new(tick())
local upPart = workspace.UpPart
local function isSide(facing, p2pVec)
local angle = math.acos(facing:Dot(p2pVec))
local deg = angle * 180/math.pi
if deg < 45 then
return true
end
end
local function isLooking(obj1, obj2)
local p2pVec = (obj2.Position - obj1.Position).unit
– check for 2
local found = isSide(obj1.CFrame.LookVector, p2pVec)
if found then
return 2
end
– check for 5
local found = isSide(-obj1.CFrame.LookVector, p2pVec)
if found then
return 5
end
– check for 3
local found = isSide(obj1.CFrame.RightVector, p2pVec)
if found then
return 3
end
– check for 4
local found = isSide(-obj1.CFrame.RightVector, p2pVec)
if found then
return 4
end
– check for 6
local found = isSide(obj1.CFrame.UpVector, p2pVec)
if found then
return 6
end
– check for 1
local found = isSide(-obj1.CFrame.UpVector, p2pVec)
if found then
return 1
end
end
local function rollDie()
die.Anchored = false
local x = rnd:NextInteger(-30, 30)
local x = rnd:NextInteger(-30, 30)
local x = rnd:NextInteger(-30, 30)
die.RotVelocity = Vector3.new(x, y, z)
wait(3)
local result = isLooking(die, upPart)
print ("Result = ", result)
wait(3)
die.Anchored = true
die.Position = Vector3.new(0, 30, 0)
end
wait(5)
rollDie()