Hey!
I was trying my best to make a DialogueGui but it dosen’t seem to work! ;-;
i just want to make the gui appear when “PortalShakeActivator” is touched by a player.
Here is the code :-
local DialougePart1 = script.Parent.PortalShakeActivator
text1 = "Waiting for players to load..."
for i = 1,#text1 do
script.Parent.Text = string.sub(text1,1,i)
wait(0.05) -- the time each words get typed in
end
local DialougePart1 = script.Parent.PortalShakeActivator
text1 = "Waiting for players to load..."
for i = 1,#text1 do
script.Parent.Text = string.sub(text1,1,i)
wait(0.05) -- the time each words get typed in
end
you didn’t include the touch detection connection in the code
lmao not sure if this has anything to do with the problem
anyways
try smth like this
assuming that PortalShakeActivator is a BasePart and all your paths are correct:
local DialoguePart1 = script.Parent:WaitForChild("PortalShakeActivator")
local dialogueGui = script.Parent:WaitForChild("DialogueGui"):WaitForChild("DialogueFrame"):WaitForChild("TextLabel")
local text1 = "Waiting for players to load..."
local function typeText(guiElement, text)
for i = 1, #text do
guiElement.Text = string.sub(text, 1, i)
task.wait(0.05) -- the time each character appears
end
end
local function onTouched(player)
if player and player:IsA("Player") then
typeText(dialogueGui, text1)
end
end
DialoguePart1.Touched:Connect(onTouched)
i didn’t just add the connection but a couple of other things:
i replaced wait(0.05) with task.wait(0.05) because wait is deprecated
i referenced paths with WaitForChild() just incase they didnt load
now, let’s say i’m wrong and PortalShakeActivator isn’t a BasePart and was a TextButton or an ImageButton. here’s what you would do:
all you need to do is change the last line
the last line is DialoguePart1.Touched:Connect(onTouched)
you need to replace the Touched with Activated
that means that it’d become DialoguePart1.Activated:Connect(onTouched)
now this is very very important:
your dialogue script is a ServerScript (for simplification, the icon in explorer is gray). it needs to be a LocalScript instead of a ServerScript so that it functions properly and doesn’t affect other players in the game (for simplification, the LocalScript icon should be blue and it should have a monitor-looking section on the bottom right of the icon).
i might’ve forgotten some things but wtv
mark me as solution if i solved your problem
local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator") -- Change Part to whatever your part is called which a player will need to touch
local gui = script.Parent
gui.TextLabel.TextTransparency = 1
TouchPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == game.Players.LocalPlayer.Character then
gui.TextLabel.TextTransparency = 1
task.wait(0.3)
gui.TextLabel.TextTransparency = 0.90
task.wait(0.3)
gui.TextLabel.TextTransparency = 0.70
task.wait(0.3)
gui.TextLabel.TextTransparency = 0.20
task.wait(0.3)
print("Gui opened")
end
end)
Okay, snaz, you’ve got it working, but I would like to introduce you to a fundamental principal that makes us stop repeating ourselves while we code, this is useful as it:
Saves us time when writing code
Makes it easier for other programmers to read.
We should also make sure that our code is as efficient as possible, this means we shouldn’t have any lines of code we don’t need.
This is my attempt at tidying up your code, I have added a list of comments below, just to let you know what I’ve changed:
local TweenService =game:GetService("TweenService")
local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator")
local gui = script.Parent
local Debounce = false
TouchPart.Touched:Connect(function(hit)
if hit.Parent.Name == game.Players.LocalPlayer.Name and Debounce == false then
TweenService:Create(gui.TextLabel, TweenInfo.new(1), { TextTransparency = 0 }):Play()
print("Gui opened")
Debounce = true
end
end)
What I changed:
Import the TweenService, this allows us to interpolate properties of instances (this allows to create easy animations).
I add something called a debounce, in short roblox will continuously fired the Touched event, even if the user is touching the part and not moving, which is not good as it will make the code execute too many times.
To counter this we add a Debounce variable, meaning as soon as we touch it, we set this variables value to True and this prevents the code which makes the TextLabel Text visible can’t run again.
I also removed the TextTransparency=1 line here as it is useless, just text TextTransparency to be inside of Roblox Studio.
Before you were checking two times, if their was a player & if the player had a specific name, I made this one check, I also check to make sure the value of the Debounce variable is false.
I then create a Tween, which I set to take 1 second, you can change the amount of seconds by ammending that line.
I then play the tween I’ve created.
I print “Gui Opened”, as you had that before.
Then I set debounce to be true so that the code can’t run again.
move UI manipulation to LocalScript: the script that manipulates the UI should be a LocalScript so it can properly access LocalPlayer and modify the player’s UI without problems.
server to client communication—if the intention is to have a server-side event (touching a part) trigger client-side behavior (changing UI transparency), you should use RemoteEvents. the ServerScript can fire a RemoteEvent when the part is touched, and a LocalScript listening to this event can then change the UI transparency/fade the UI.
ok this is how i would structure it with RemoteEvents:
this is the ServerScript:
local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator")
local remoteEvent = game.ReplicatedStorage:WaitForChild("YourRemoteEventName") -- pls make sure you have a RemoteEvent under ReplicatedStorage and adjust the path
TouchPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
remoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent)) -- this line fires the event for the player who touched the part
end
end)
this is the LocalScript (child of the UI):
local remoteEvent = game.ReplicatedStorage:WaitForChild("YourRemoteEventName")
local gui = script.Parent
remoteEvent.OnClientEvent:Connect(function()
--do what @Noah mentioned about `TweenService`
end)
ignore the deleted post above, sent it on accident while typing
nooo i js took a closer look and read your paths and realized (i js skimmed through it)—i was under the assumption that the part was using script.Parent and the LocalScript was in Workspace, and LocalScripts cannot be run in Workspace (assuming you didn’t have Client as the RunContext in a ServerScript)
i flipped it in the version i just sent and even if that was the case my silly mind wouldn’t have thought of moving it and replacing the paths like you did. but yeah that would work and there’s no need for anything i said, ignore that—i misread your code and that misled me