Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make two scripts run at the same time?

Asked by 4 years ago

I'm trying to make a model of mine appear to be talking like an actual player, so it talks both in the chat and also has a bubble chat above its head. (The model doesn't have anything special to it, there is actually an invisible talking dummy that is lined up with my model's head so it looks like my model is talking) Both scripts have the same timing, but I came across an annoying problem when playing the game.

The chat bar isn't in sync with the bubble chat despite being the same timing. I'm assuming it's because of the time it takes for a player to load in, resulting in one script running before the other.

Is there a way I could get both scripts to synchronize?

The script for the bubble chat is placed in a dummy with humanoid (the script itself isn't in the humanoid) and I made the dummy parts invisible and not collidable as if there was no dummy at all, making it appear that my model is actually talking. Here's the script for that (not the complete script, just the beginning, and end).

while true do
wait(3) --time till it speaks the message below
game:GetService("Chat"):Chat(script.Parent.Head, "Oh...", Enum.ChatColor.White) --first thing it says
wait(6)
game:GetService("Chat"):Chat(script.Parent.Head, "Hello there.", Enum.ChatColor.White)
wait(1)
game:GetService("Chat"):Chat(script.Parent.Head, "", Enum.ChatColor.White) --the only way to make it stop speaking or else it would loop for some reason
end

My next script, where he talks in the actual chat, is placed in StarterPlayerScripts. Here is the script for that.

Wait (3) --timing is the same as above
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ --it gets the StarterGui and calls a function   
Text = "[Dipper]: Oh..."; --model name and message
Color = Color3.new(0, 0, 200); --this is just color, ignore this
FontSize = Enum.FontSize.Size24; --font, ignore
}) --below is the same thing but different message, and it just goes on and on
Wait(6) 
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ 
Text = "[Dipper]: Hello there."; 
Color = Color3.new(0, 0, 255);
FontSize = Enum.FontSize.Size24; 
})

Hopefully, there is a script I can do so that these two scripts are in sync. If you're confused with anything, here's the game so you have a better picture of what's going on and help me. http://www.roblox.com/games/4714225379/A-Talk-With-Dipper-wip

Thank you for any help.

0
You could combine both of these scripts into one single script in a LocalScript and they will run simultaneously, I think. killerbrenden 1537 — 4y
0
Since you CAN use the service Chat in a LocalScript and the service StarterGui ONLY in a LocalScript. So, combining these will be client sided and probably be correct timing, I assume. killerbrenden 1537 — 4y
0
Both scripts are in two different parts though. One is in workspace and one is in playerscripts Aprilsaurus 48 — 4y

1 answer

Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
Edited 4 years ago

Just keep one script. Its overall better. Use spawn() to run a loop and some code at the same time.

spawn(function()
    while true do
        print('Spawn functions allow you to run 2 loops at the same time!')
    end
end)
spawn(function()
    while true do
        print('I use spawns in every single fps game I make!')
    end
end)
spawn(function()
    while true do
        print('Try it!')
    end
end)

Heres a full script:

spawn(function()
    while true do
    wait(3) --time till it speaks the message below
    game:GetService("Chat"):Chat(script.Parent.Head, "Oh...", Enum.ChatColor.White) 
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{  
        Text = "[Dipper]: Oh...";
        Color = Color3.new(0, 0, 200); 
        FontSize = Enum.FontSize.Size24;
    }) 

    wait(6)
    game:GetService("Chat"):Chat(script.Parent.Head, "Hello there.", Enum.ChatColor.White)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ 
    Text = "[Dipper]: Hello there."; 
    Color = Color3.new(0, 0, 255);
    FontSize = Enum.FontSize.Size24; 
    })
    wait(1)
    game:GetService("Chat"):Chat(script.Parent.Head, "", Enum.ChatColor.White)
    break -- Ends the loop. But why put it in a loop anyways?
    end
end)

-- Putting it in a loop was kinda stupid, so...

wait(3) --time till it speaks the message below
    game:GetService("Chat"):Chat(script.Parent.Head, "Oh...", Enum.ChatColor.White) 
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{  
        Text = "[Dipper]: Oh...";
        Color = Color3.new(0, 0, 200); 
        FontSize = Enum.FontSize.Size24;
    }) 

    wait(6)
    game:GetService("Chat"):Chat(script.Parent.Head, "Hello there.", Enum.ChatColor.White)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ 
    Text = "[Dipper]: Hello there."; 
    Color = Color3.new(0, 0, 255);
    FontSize = Enum.FontSize.Size24; 
    })
    wait(1)
    game:GetService("Chat"):Chat(script.Parent.Head, "", Enum.ChatColor.White)

0
But where would I have to place this script in? Would I have to delete one of my scripts or something? Just kind of confused because one script HAS to be in starterplayscripts and one HAS to be in workspace Aprilsaurus 48 — 4y
Ad

Answer this question