Wait() is Breaking my script (wanting to play HoloGram at the same time on both ends)


This is the problem im having.

This is the part of the script i know is breaking it because its fine if i remove it.

Replicated.HoloLinkFolder.SendMessage.OnServerEvent:Connect(function(player, text)
    for _,Player in ipairs(game:GetService("Players"):GetPlayers()) do
        local character = Player.Character
        if character then
            character:FindFirstChild("Part").Holo.Transparency = 0.5
            character:FindFirstChild("Part").MessageGUI.Enabled = true  
            character:FindFirstChild("Part").MessageGUI.Frame.Message.Text = text
            wait(4)
            character:FindFirstChild("Part").Holo.Transparency = 1
            character:FindFirstChild("Part").MessageGUI.Enabled = false  
            character:FindFirstChild("Part").MessageGUI.Frame.Message.Text = ""
        end
    end
end)

Please let me know how to fix this.

It’s because it yields the thread, so it changes t he text, waits 4 seconds and thens removes it and then does it for the next player

Use a coroutine

Replicated.HoloLinkFolder.SendMessage.OnServerEvent:Connect(function(player, text)
    for _,Player in ipairs(game:GetService("Players"):GetPlayers()) do
		coroutine.wrap(function()
			local character = Player.Character
			if character then
				character:FindFirstChild("Part").Holo.Transparency = 0.5
				character:FindFirstChild("Part").MessageGUI.Enabled = true  
				character:FindFirstChild("Part").MessageGUI.Frame.Message.Text = text
				wait(4)
				character:FindFirstChild("Part").Holo.Transparency = 1
				character:FindFirstChild("Part").MessageGUI.Enabled = false  
				character:FindFirstChild("Part").MessageGUI.Frame.Message.Text = ""
			end
		end)()
    end
end)
1 Like

Thank you it works, Works perfectly.

1 Like