So I’ve got this simple system for doing hints in my game. Basically, any serverscript can fire the HintEvent with a string that it will show, and a local script under the playerscripts will show the text with a Hint Object. Yes, i know that hints are deprecated, but they aren’t broken in at all. Anyways, my issue is that the hint just shows the first letter of the hint without going through each character. I think the issue might have something to do with my usage of coroutines. Im new to using them and not sure if im doing it right. Anyways, heres the Script under a part in the workspace, and the local script.
Part Script:
local HintEvent = game.ReplicatedStorage.HintEvent
local Part = script.Parent
local ClickDetector = Part.ClickDetector
ClickDetector.MouseClick:Connect(function(Player)
HintEvent:FireClient(Player, "This a test for the Hint System, to make sure all is in working order.")
end)
LocalScript:
local SoundService = game:GetService("SoundService")
local HintEvent = game.ReplicatedStorage.HintEvent
local Gui = script.Parent
local CurrentHint = nil
local CurrentLoop = nil
HintEvent.OnClientEvent:Connect(function(Text: string)
if CurrentLoop ~= nil then
coroutine.close(CurrentLoop)
CurrentHint:Destroy()
end
local Hint = Instance.new("Hint")
Hint.Parent = Gui
CurrentHint = Hint
CurrentLoop = coroutine.create(function()
for i, v in pairs(Text:split("")) do
Hint.Text = Hint.Text..v
SoundService:PlayLocalSound(script.Sound)
wait(0.05)
end
wait(3)
Hint:Destroy()
CurrentHint = nil
CurrentLoop = nil
end)
coroutine.resume(CurrentLoop)
end)
You can use #string to get the full length of a string, that taken into account we could:
local my_string = "This is a string!"
for i = 1,#my_string do
local current = string.sub(my_string, i, i)
Hint.Text = Hint.Text..current
task.wait(.05)
end
This works better for what i wanted, but the hint still just shows “T”. Im not sure this has to do with the for loop but instead my usage of coroutines which im VERY unfamiliar with.
I have tried your code in Studio after my edit and it seems to work just fine…
local SoundService = game:GetService("SoundService")
local HintEvent = game.ReplicatedStorage.HintEvent
local Gui = script.Parent
local CurrentHint = nil
local CurrentLoop = nil
HintEvent.OnClientEvent:Connect(function(Text: string)
if CurrentLoop ~= nil then
coroutine.close(CurrentLoop)
CurrentHint:Destroy()
end
local Hint = Instance.new("Hint")
Hint.Parent = Gui
CurrentHint = Hint
CurrentLoop = coroutine.create(function()
for i = 1,#Text do
local current = string.sub(Text, i, i)
Hint.Text = Hint.Text..current
task.wait(.05)
end
wait(3)
Hint:Destroy()
CurrentHint = nil
CurrentLoop = nil
end)
coroutine.resume(CurrentLoop)
end)
Oh i see that your code doesnt have the playsound function being used. So it seems it definitely has something to do with the sound thing. Everything works perfectly when i comment the sound thing out