My code sucks help please and thank you

aight its probably my fault but this code for a simple diologue box shows the gui for every one in the server once activated. it works fine tho but yknow its kinda not what i wanted so what do i need to change here (id really apriciate it if you just gave me some hints on how to fix this instead of how to actually fix it)
thanks in advance


local triggerpart = game.Workspace.eternaldiologue.ProximityPrompt

triggerpart.Triggered:Connect(function()
	triggerpart.Enabled = false
	script.Parent.Visible = true
	script.Parent.Text = "hey there welcome to my game iam still working on this so please be patient while i try my best "
	wait(5)
	script.Parent.Text = "btw if you are rok tell me if you want this code"
	wait(5)
	script.Parent.Text = "aight got to go work right now so see you later"
	wait(3)
	script.Parent.Visible = false
	triggerpart.Enabled = true
end)

2 Likes

Hey!
The first things I’d change is to replace the usage of wait() with task.wait(), as wait() is considered depricated.
See:

I’d also place script.Parent in a variable, just for easier readability. Right now, its not obvious to me what script.Parent is, whilst if you named it textLabel or something similar, then I’d know immediately.

1 Like

I put the script in startergui inside that there’s screen GUI inside that is a text label which contains the script (iam not 100% tho I’ll check if I’m correct later as I’m busy rn)

1 Like

Eternaldiologue is the name of the part that contains the proximitypromprt

1 Like

If it shows for everyone, that would probably mean you are using a script in a server side environment.
To use a local environment, you should use a LocalScript or change the RunContext of the Script to Client.

1 Like

I’ll try that and update you on it

1 Like

When I turn it into a local script it doesn’t work
It says that eternaldiologue is not a valid member of workspace (eternal dialogue is the part with the proximity prompt)

1 Like

Then you probably have streaming enabled while your script is not streaming ready.
If you have a small game, you can turn streaming off, if it has a big map you should make your script streaming ready or at least load the part in a persistent model and wait for the persistent models to have loaded.

The easiest, less neat but also less hard way is to change

local triggerpart = game.Workspace.eternaldiologue.ProximityPrompt

to

local triggerpart = workspace:WaitForChild("eternaldiologue").ProximityPrompt
1 Like

Apologies for being late to the point where you probably don’t need this help anymore, but this is happening because the LocalScript is trying to get the eternaldialogue part before it is loaded. This can be fixed by adding task.wait(1) at the beginning of the script. If this still doesn’t work, increase the duration.

Additonally, in your code you could utilize functions. For example, when you are changing the text of script.Parent and then waiting, you could instead create a function that passes a text parameter and sets the script.Parent.Text to the parameter. Additionally, you could have a wait parameter which tells the function how long to wait.

Keep in mind, this is a really small optimization, and in all honesty for code this small it really is unnecessary. However, it is good practice to prevent things getting out of hand in your future scripts.

came back when the new code broke for no reason lol

Hey, I wouldn’t use this solution because this can be wildly unreliable! Use the way @CodeProto mentioned. The error that occurs is the purpose for Instance:WaitForChild existing.

Even better, do:

local triggerPart = workspace:WaitForChild("eternaldiologue"):WaitForChild("ProximityPrompt")

This makes 100% sure that the instance is found by the script. It’s important to practice this because even though there is a small chance of it erroring, the chance an error occurs increases for every time you do this for another part. This will make debugging a living nightmare!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.