So i was planning to add dialogues to my test game, but when I tried to add it there was a problem that I don’t know how to solve. So we all know that to access the playergui we need to do it on a local script, but the changes won’t be made because well it is on a local script. I tried doing this on a normal script but got an error because you cant use “LocalPlayer” in it. Any solutions?
Local Script:
local Player = game:GetService("Players")
local DialougeText = Player.LocalPlayer.PlayerGui.ScreenGui.DialougeFrame.DialougeText
print("Script starting")
Player.PlayerAdded:Connect(function()
DialougeText.Text = "After bypassing a heck lot of security, i can now finally see the vault it self! I just need to avoid this lasers..."
print("waiting")
wait(5)
print("waiting done")
repeat
DialougeText.Transparency = DialougeText.Transparency + 0.1
wait(0.01)
until
DialougeText.Transparency == 0
print("Dialouge text gone")
end)
local Player = game:GetService("Players")
print("Script starting")
Player.PlayerAdded:Connect(function(player)
local DialougeText = player.PlayerGui.ScreenGui.DialougeFrame.DialougeText
DialougeText.Text = "After bypassing a heck lot of security, i can now finally see the vault it self! I just need to avoid this lasers..."
print("waiting")
task.wait(5)
print("waiting done")
repeat
DialougeText.Transparency += 0.1
task.wait(0.01)
until
DialougeText.Transparency == 1
print("Dialouge text gone")
end)
Make it a server script. You could also use RemoteEvents.
local Player = game:GetService("Players")
local DialougeText = Player.LocalPlayer.PlayerGui.ScreenGui.DialougeFrame.DialougeText
print("Script starting")
Player.PlayerAdded:Connect(function()
DialougeText.Text = "After bypassing a heck lot of security, i can now finally see the vault it self! I just need to avoid this lasers..."
print("waiting")
wait(5)
print("waiting done")
repeat
DialougeText.TextTransparency = DialougeText.TextTransparency + 0.1
wait(0.01)
until
DialougeText.TextTransparency == 1 << here
print("Dialouge text gone")
end)
My apologies for all of these other replies being from inexperienced “Devs” who have 0 clue what they are doing, Try this instead:
print("Script starting")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local DialougeText = plr.PlayerGui.ScreenGui.DialougeFrame.DialougeText
DialougeText.Text = "After bypassing a heck lot of security, i can now finally see the vault it self! I just need to avoid this lasers..."
print("waiting")
wait(5)
print("waiting done")
repeat
DialougeText.Transparency = DialougeText.Transparency + 0.1
wait(0.01)
until
DialougeText.Transparency == 1
print("Dialouge text gone")
end)
I don’t think you need to put the player added if you put it in starter player scripts just change the local DialougeText = Player.LocalPlayer:WaitForChild("PlayerGui").ScreenGui.DialougeFrame.DialougeText
and remove the player.playeradded. Plus, put the script in StarterPlayerScripts.
I didn’t notice the Transparency problem, but also, the actual problem was with the script not running. The problem wasn’t about changing the transparency, it was about how he didn’t know how to reference the player on the server.
You really shouldn’t be going around calling people inexperienced just because someone was trying to help.
You don’t need to have a PlayerAdded event handler on the client. The reason for this is that the script will run when the client loads, if the script is in one of the designated locations for local scripts, such as StarterPlayer → StarterPlayerScripts.
Another way you could do this is by using a remote event and have the server dictate what text the player sees. You could also implement a system which will vary the wait time based on the length of the text --OR-- just place a big red ‘X’ on the top right corner of the dialog box and let the player close the window at their convenience.
-- ******** Server Script
local playerService = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
playerService.PlayerAdded:Connect(function(player)
local text = "After bypassing a heck lot of security, i can now finally see the vault it self! I just need to avoid this lasers..."
replicatedStorage.Events.SendDialogText:FireClient(player, text)
end)
-- ******** Client Script
local playerService = game:GetService("Players")
local childWaitTime = 10
-- Fades in the dialog over one second.
local function dialogFadeIn(object)
local trans = 1
while trans > 0 do
task.wait(0.1)
trans -= 0.1
object.Transparency = trans
end
object.Transparency = 0
end
-- Fades out the dialog over one second.
local function dialogFadeIn(object)
local trans = 0
while trans < 1 do
task.wait(0.1)
trans += 0.1
object.Transparency = trans
end
object.Transparency = 1
end
-- Function that returns a delay (in seconds) based on the number of words in
-- a string. Minimum return value is 5.
local function textDelayValue(str)
local strArray = string.split(str, " ")
local dtime = 5 + (#strArray * 0.75)
return dtime
end
replicatedStorage.Events.SendDialogText.OnClientEvent:Connect(function(displayText)
local localPlayer = playerService.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui", childWaitTime)
if playerGui then
local screenGui = playerGui:WaitForChild("ScreenGui", childWaitTime)
if screenGui then
local dialougeFrame = gameGui:WaitForChild("DialougeFrame", childWaitTime)
if dialougeFrame then
dialougeText = dialougeFrame:WaitForChild("DialougeText", childWaitTime)
if dialougeText then
dialougeText.Transparency = 1
dialougeText.Text = displayText
ScreenGui.Enabled = true
dialougeFrame.Visible = true
dialougeText.Visible = true
dialogFadeIn(dialougeText)
task.wait(textDelayValue(displayText))
dialogFadeOut(dialougeText)
dialougeText.Visible = false
end
end
end
end
end)