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

Running on DialogChoice?

Asked by 9 years ago

So, I have been working on this 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 it so that this script runs when a dialog is clicked? And, what should this script's parent be (the dialog? anything? Workspace?)

1 answer

Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
9 years ago

Dialogs have a DialogChoiceSelected event that is triggered whenever a player clicks on a dialog choice under that Dialog.

http://wiki.roblox.com/index.php?title=API:Class/Dialog/DialogChoiceSelected

So if you make the script's parent the dialog, you could just write code like this:

local dialog = script.Parent

dialog.DialogChoiceSelected:connect(function(player, dialogChoice)
    if (dialogChoice.Name == "Name of your dialog choice goes here") then
        onClicked()
    end
end)
0
Where would I input my actually function for that though? I am not used to calling functions the way that you did. corncob567 275 — 9y
0
On line 5 you can see that I call your onClicked function Merely 2122 — 9y
0
Thanks very much for the help, but I am asking where I should add your script, to mine? Should I put it after everything, inside of my function, or before everything? I'm relatively new to scripting, so I need all the help I can get. Sorry for the trouble. corncob567 275 — 9y
Ad

Answer this question