There are a few ways to accomplish this though for the sake of simplicity I’m only going to deep-dive into one.
So, to execute this dialogue system we are going to be using a combination of Touched
, FireClient
, and some basic UI tools.
Place down a simple part and insert a script into it like so:
Let’s open up this script and see what we can do. First off, we need to establish when the part gets touched initially. To do this we can use [part].Touched
, in this case it would be script.Parent.Touched
, to identify when another part comes into contact with the main part.
script.Parent.Touched:Connect(function(hit)
end)
Now as you notice, I’ve paired in the argument “hit”, as Touched
will always return the part that it detected. Next, we need to determine whether or not it was a player who touched this brick, to do so we can implement a simple sanity check.
script.Parent.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
end
end)
Now since we have that code inside of the if/then statement will only run if the part has a parent, and the part’s parent has a child named “Humanoid”.
From there, you’ll need to add a RemoteEvent into ReplicatedStorage, for now let’s just name it DialogueEvent.
Back in the main script, we can now connect this event to coincide with our Touched
event. To do this I’ve employed two functions, RemoteEvent:FireClient and game.Players:GetPlayerFromCharacter.
script.Parent.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.DialogueEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
end)
It’s also important to add a debounce so that the part doesn’t spam the notification when a player walks on it, I’ve done that here:
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if not debounce then
debounce = true
game.ReplicatedStorage.DialogueEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
wait(5)
debounce = false
end
end
end)
Now with that side of the scripting finished, we need to look at altering the client. Let’s start by making a ScreenGUI with a TextLabel inside of it, this can always be changed later to fit your needs, then insert a LocalScript inside of that TextLabel.
Now, let’s start off this script by connecting it to the RemoteEvent we used earlier:
game.ReplicatedStorage.DialogueEvent.OnClientEvent:Connect(function()
end)
Since no parameters were sent through the FireClient
function, we don’t need to add any arguments here.
From here it’s very simple, just editing the text in the textbox and then setting the visibility to false.
game.ReplicatedStorage.DialogueEvent.OnClientEvent:Connect(function()
script.Parent.Text = "This is a dialogue label"
wait(5)
script.Parent.Visible = false
end)
You can make this more or less complex should you choose to, however this is barebones what you would need to create a dialogue system.