Ok, so basically I have this Typewriter effect that’s meant to work but it’s not. I’m not sure if it’s because the function is in the wrong place or because of other reasons, but any help would be greatly appreciated, thanks.
local message = script.Parent.Timer -- Timer
local players = game:GetService("Players")
game.ReplicatedStorage.Remotes.RemoteEvent.OnClientEvent:Connect(function() -- Timer Remote
print("got")
for i = 3, 0, -1 do -- Countdown
message.Text = i
print(i)
wait(1)
if i == 0 then
print("finished")
local Chosen = players:GetPlayers()[math.random(#players:GetPlayers())] -- Randomly choose a player
print(Chosen.Name) -- Stops at this print
--- Anything after the above print doesn't run ---
wait(.1)
--- TypeWriter Function
local function typewrite(object,text,length)
for a = 1, #text, 1 do
object.Text = string.sub(text, 1, 1)
wait(length)
end
typewrite(message, " The Killer is: " .. Chosen.Name, 0.1)
print("Done") -- This print doesn't run
end
end
end
end)
local function typewrite(object, text, length)
for i = 1, text:len() do
object.Text = string.sub(text, 1, i);
wait(length);
end
end
You set it the third argument of [color=teal]string.sub[/color] to [color=teal]1[/color], which is why it should only be stuck at one. But if you set it to I, it should work.
Oh shoot, I forgot to mention that they’re are different.
The countdown should use for i, and the typewrite something else. But, regardless it doesn’t print or show on the gui. Basically the entire function doesn’t run.
Yeah actually, that’s the main reason. You should move everything out of the for loop as you aren’t supposed to do this. Keep it in another scope, and make your own custom event using BindableEvents, which you can fire and then do everything there. Here.
local myCustomEvent = Instance.new("BindableEvent");
local message = script.Parent.Timer;
local players = game:GetService("Players");
game.ReplicatedStorage.Remotes.RemoteEvent.OnClientEvent:Connect(function()
print("got");
for i = 3, 0 do
message.Text = i;
print(i);
wait(1);
if print i == 0 then
myCustomEvent:Fire();
break
end
end
end)
myCustomEvent.Event:Connect(function()
print("finished");
local Chosen = players:GetPlayers()[math.random(#players:GetPlayers())];
print(Chose.Name);
wait(.1);
local function typewrite(object, text, length)
for i = 1, #text do
object.Text = string.sub(text, 1, i);
wait(length);
end
typewrite(message, "The Killer is: " .. Chosen.Name, 0.1);
print("Done");
end
end)
Hmmhmm you were right. I accidentally replaced i with 1. I think I also misplaced this line:
typewrite(message, " The Killer is: " .. Chosen.Name, 0.1)
print("Done") -- This print doesn't run
Should have been 1 end lower. Thanks for you help
Updated Code:
local function typewrite(object, text, length)
for a = 1, #text, 1 do
object.Text = string.sub(text, 1, a)
wait(length)
end
end
typewrite(message, "The Killer is: " .. Chosen.Name, 0.1)
wait(1)
typewrite(message, "Survivors avoid the killer... At all costs", 0.1)