Script doesn't fonction

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

wait(5)
rollDie()

Formatted code so it’s less painful to read

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()

What exactly doesn’t function?

2 Likes

What is the output message, errors?

1 Like

Doesn’t work, sorry. Do you have other script?

he don’t put a message about the error

Poke was just formatting the code for us to see more clearly

Is there anything Outputting at all? Can you check your Ouptut by heading to the “View” category in Studio, then finding the “Output” tab?

2 Likes

1 Like

Epic

This line right here is erroring, as there’s nothing in the workspace that’s named UpPart as soon as the script starts

3 Likes