Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Running on DialogChoice?

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

✓ Accepted answer

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)

3 comments

0

Where would I input my actually function for that though? I am not used to calling functions the way that you did.

0

On line 5 you can see that I call your onClicked function

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.