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

How do you make an NPC kick someone if they choose a certain dialogue option?

I need to know how to make an NPC kick someone if they choose a dialog choice. if a certain choice is picked, the player is kicked from the game. Here's what I've got:

workspace.Dialog.DialogChoiceSelected:connect(function(player,choice)
	 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
     player:Kick("")
end)

1 comment

0

Do you need to get the player on line 2 if it's the first argument of the function on line 1? Anyways, try player:Destroy() maybe.

1 answer

You're on the right track! So, what's important to know (and I'm unaware if you're already doing this) is that DialogChoiceSelected is a client-side event only, and therefore needs to be in a local script of sorts. Other than that, you essentially have it down. With your "choice" parameter in the function / event, you have the DialogChoice instance itself. When I tested things out, I (personally) named the DialogChoice something like "KickAction," and ran a simple if choice.Name == "KickAction" then to check if they selected the choice we want to kick them for. The only thing you have to make sure is that you don't name any other dialog choices "KickAction," or whatever you name the deadly dialogue option. Then just put your player:Kick("") nestled in the "if then" statement. You should be good!

The code I used in my testing place is as follows:

--Local Script
local d = workspace.Part.Dialog --in your script, locate the actual parent dialog instance.
d.DialogChoiceSelected:Connect(function(p, c) --p being player, c being choice
	if c.Name == "KickAction" then --the name of the dialog choice doesn't matter, just make sure it lines up with the name you check for on this line, and no other dialog choice has this name.
		p:Kick("bruh") --"bruh" can be any message you want.
	end
end)

Hope this helped! Make sure to accept this as an answer if it solved your problems :)

1 comment

0

nice, i never knew how to connect dialog choices to a script. Ill use this script as a resource. (Im not question dude lol)

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