game.ReplicatedStorage.SendText.OnClientEvent:Connect(function(text)
script.Parent.Visible = true
for i = 1, #text do
sound:Play()
script.Parent.Ticker.Text = string.sub(text, 1, i)
task.wait(0.04) --This is the speed of the text
if i == #text then
task.wait(4)
script.Parent.Visible = false
end
end
end)
I’m trying to make it so that “bar” is said immediately after “foo” decays (1.8 seconds, the amount of time it takes for the text to tick, + 4, the decay time)
but what really happens is that “bar” becomes invisible due to foo’s decay timer. now if I made it wait 6.8 seconds it works but then there’s too big of a gap between the chats. if I made it 5.9 seconds the same problem occurs.
I need to make the localscript and the server script work in sync so that there is no gap between foo being said and bar being said, and “bar” is not made invisible by foo’s decay.
I was thinking about using a remoteevent but I didnt want an exploiter to be able to completely disable everyone’s ability to see the npc’s chat so I was wondering if there would be any way to code it so that the exploiter could only disable their own ability to see the chat?
local textThread
SendText.OnClientEvent:Connect(function(text: string)
if textThread then task.cancel(textThread) end
textThread = task.spawn(function()
script.Parent = true
for I = 1, #text do
script.Parent.Ticket.Text = string.sub(text, i, i)
task.wait(0.04)
end
script.Parent.Visible = false
end
end)
use task.spawn or coroutines to create a thread and cancel it so the for i loop stops and start new one immediately
Are you sure this is the best way to do it? I don’t want to have to manually type into a calculator the amount of characters in the text times 0.04 plus 3 to put into task.wait() in the server script every time.
So your method works, it allows for no gap between the chat boxes appearing because it’s instantly cancelled once a new one is sent by the server script, but you see the time it takes for a chat box to be written on the client is 0.04 seconds every character. And so in the server script, it waits 0.04 seconds for every character in the text.
But the problem is I need to manually figure out how many characters in the text there are, then type that into a calculator to get a number which I then put bare into the server script.
There’s always going to be a delay between server and client, due to network ping.
Also exploiters cannot prevent other players from receiving remote events, unless you somehow end up writing vulnerable code.
If possible, I’d suggest moving the dialogues completely on the client, and using remotes only to signal the clients that dialogues should prompt. You could write a configuration with dialogue chains, that will automatically follow up, instead of relying on multiple remote fires.