So, I tried doing this script last night and it still didn’t work after I tried many times. Why won’t the script work/GUI load?
I’ve searched on the DevForum, I tried the Touched event, and ClickDetector, and now I’m doing ProximityPrompt. If I enable the GUI normally, it still loads… normally.
The starter GUI isn’t accessible once the game is running, you need to reference the player’s playerGui.
If you add the player argument into the function you should be able to use that to get the playerGui
Consider adding :WaitForChild methods into this, as it is replicated into PlayerGui from StarterGui (which takes a minimal but noticeable amount of time). If it is right at the start of script execution, it’ll most likely error out as it hasn’t finishing loading into the player.
This may sound complicated for now, but I think a better method would be to use a function provided by another script instead (using BindableEvents or ModuleScripts), so that the system is generally more efficient (No need to copy & paste all that code every time, and the code is situated in one script for easy maintenance).
Even better, just use the ProximityPromptService in a single server script (in ServerScriptService for security), along with CollectionService to use tags (using the Tag Editor) to identify if it’s a dialogue prompt, then use the prompt instance to search to get it’s relevant information, whether it’s through a dictionary, or through attributes.
It would be best to save this for future reference if you ever want to challenge yourself. c:
I’m not familiar with ProximityPromptService that well or anything like ModuleScripts lol. I can see if I can try copying the scripts on at least one of the pages but other than that, I’ve got no idea what I’m doing.
Fortunately, I’m here to help. Unfortunately, I only have ~30min as of starting this.
If you want, I could quickly put together a model with all the things I’ve described to you just now, but I don’t think that’s a good way to learn.
I’d suggest setting your script up like this:
local PPS = game:GetService("ProximityPromptService")
local CS = game:GetService("CollectionService")
PPS.PromptTriggered:Connect(function(promptInstance, triggeringPlayer) -- Here, we connect to ProximityPromptService's .PromptTriggered event, which returns the prompt and the player who triggered it
if CS:HasTag(promptInstance, "dialoguePrompt") then -- We use CollectionService to check if the prompt has the tag "dialoguePrompt" (assign this in the Tag Editor window)
local dialogueUI = triggeringPlayer.PlayerGui.dialogue:WaitForChild("Frame")
dialogueUI.Visible = true
dialogueUI.image.ImageLabel.Image = 0
dialogueUI.user.UserName.Text = triggeringPlayer.Name -- You can change this to any other string if you wanted to
dialogueUI.desc.TheirDesc.Text = promptInstance:GetAttribute("desc") -- This will get the string stored in an attribute of the prompt named "desc"
end
end)
I have included some comments to describe what the code is doing.
You should try figure the rest out from here. This code is based on what you provided in the original post.
One problem with this is that it only allows for one string to be shown at the moment. However, you could fix this by making a dictionary that contains all the strings for one prompt, with the key being the name of the prompt, or an attribute.
Had to rush this since I need to go now, lol.
HINT:
(All you need to do is add the “desc” attribute to the prompt, and give it the tag “dialoguePrompt” using the Tag Editor window, under the View tab c: )
I have seen! But, since I am a quite new scripter, and I usually just watch a bunch of YouTube tutorials, I wanted to see if I could do anything different for a bit!