Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a DialogChoice Function?

Asked by 9 years ago

So, I've been working on the following script for a while:

local elevator = game.Workspace.Elevator --shorter for typing purposes

--this is a short for loop to find the first Part in the elevator

for i, v in pairs(elevator:GetChildren()) do
if v:IsA("BasePart") then --all part types inherit from basepart therefore they're all baseparts
elevator.PrimaryPart = elevator.door2 -- set the primary part
break -- break statement will stop the for loop and go back up scope
end
end


function onClicked()
elevator.door2.CanCollide = true
for i = 1, 20, 1 do
elevator.door2.Transparency = elevator.door2.Transparency - .05
wait(.05)
end
for i = 1, 800 do
elevator:SetPrimaryPartCFrame(elevator:GetPrimaryPartCFrame() * CFrame.new(0, -0.1, 0))
wait(.01)
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

How can I make this script be performed when a DialogChoice/Dialog is selected? Rather than functioning onClicked, would it be something like DialogChoiceSelected?

0
Please use the Lua Block for your code. This is done by Press the Blue Icon that say's "Lua" and pasting your code in-between the "~~~~~" lines. alphawolvess 1784 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

You'd have to put this script under a Dialog instance directly, but you could do this:

local elevator = game.Workspace.Elevator --shorter for typing purposes

for i, v in pairs(elevator:GetChildren()) do
if v:IsA("BasePart") then --all part types inherit from basepart therefore they're all baseparts
elevator.PrimaryPart = elevator.door2 -- set the primary part
break -- break statement will stop the for loop and go back up scope
end
end

local d = script.Parent.DialogChoice1 --You'd have to make a DialogChoice instance named DialogChoice1

function onClicked(c, p) --Set this to accept 2 parameters, choice and player
    if c = d then
        elevator.door2.CanCollide = true
        for i = 1, 20, 1 do
            elevator.door2.Transparency = elevator.door2.Transparency - .05
            wait(.05)
        end
        for i = 1, 800 do
            elevator:SetPrimaryPartCFrame(elevator:GetPrimaryPartCFrame() * CFrame.new(0, -0.1, 0))
            wait(.01)
        end
    end
end

script.Parent.DialogChoiceSelected:connect(onClicked())

I'm pretty sure this'd work, then. I hope, at least. Not sure, because I don't have the same workspace as you right now.

0
I don't understand. I tried that script out (I put it in the Dialog that the proper DialogChoice was located in) and it didn't work. Why is this? What do you mean by "Set this to accept 2 parameters, choice and player"? corncob567 275 — 9y
Ad

Answer this question